这是indexloc提供的服务,不要输入任何密码
Skip to content

Order not respected in union of types including str #127

@maurosilber

Description

@maurosilber

According to the docs, the order of the types in the union is respected. But when using str, it seems that it always wins:

from pydantic_xml import BaseXmlModel, attr

class Model(BaseXmlModel):
    x: float | bool = attr()
    y: bool | float = attr()
    z: str | float = attr()
    w: float | str = attr()

Model.from_xml("<Model x='1' y='1' z='1' w='1' />")

Output:

Model(x=1.0, y=True, z='1', w='1')

Expected:

Model(x=1.0, y=True, z='1', w=1.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions