compat
xsdata.formats.dataclass.compat
FieldInfo
Bases: Protocol
A class field info wrapper.
Source code in xsdata/formats/dataclass/compat.py
12 13 14 15 16 17 18 19 |
|
ClassType
Bases: ABC
An interface for class types like attrs, pydantic.
Source code in xsdata/formats/dataclass/compat.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
any_element
abstractmethod
property
Return the AnyElement used to bind wildcard element nodes.
derived_element
abstractmethod
property
Return the DerivedElement used to bind ambiguous element nodes.
any_keys
property
Return the field names of the AnyElement class.
derived_keys
property
Return the field names of the DerivedElement class.
is_model(obj)
abstractmethod
Return whether the given value is binding model.
Source code in xsdata/formats/dataclass/compat.py
47 48 49 |
|
verify_model(obj)
abstractmethod
Verify the given value is a binding model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | Any | The input model instance | required |
Raises:
Type | Description |
---|---|
XmlContextError | if not supported |
Source code in xsdata/formats/dataclass/compat.py
51 52 53 54 55 56 57 58 59 60 |
|
get_fields(obj)
abstractmethod
Return the models fields in the correct mro ordering.
Source code in xsdata/formats/dataclass/compat.py
62 63 64 |
|
default_value(field, default=None)
abstractmethod
Return the default value or factory of the given model field.
Source code in xsdata/formats/dataclass/compat.py
66 67 68 |
|
default_choice_value(choice)
abstractmethod
Return the default value or factory of the given model field choice.
Source code in xsdata/formats/dataclass/compat.py
70 71 72 |
|
score_object(obj)
Score a binding model instance by its field values types.
Weights
- None: 0
- str: 1
- *: 1.5
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | Any | The input object | required |
Returns:
Type | Description |
---|---|
float | The float score value. |
Source code in xsdata/formats/dataclass/compat.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
ClassTypes
A class types registry.
Attributes:
Name | Type | Description |
---|---|---|
types | dict[str, ClassType] | A name-instance map of the registered class types |
Source code in xsdata/formats/dataclass/compat.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
__init__()
Initialize the registry.
Source code in xsdata/formats/dataclass/compat.py
117 118 119 |
|
register(name, fmt, **_)
Register a class type instance by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | The name of the class type | required |
fmt | ClassType | The class type instance | required |
**_ | Any | No idea :( | {} |
Source code in xsdata/formats/dataclass/compat.py
121 122 123 124 125 126 127 128 129 |
|
get_type(name)
Get a class type instance by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | The class type name | required |
Returns:
Type | Description |
---|---|
ClassType | The class type instance |
Raises:
Type | Description |
---|---|
KeyError | If the name is not registered. |
Source code in xsdata/formats/dataclass/compat.py
131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
Dataclasses
Bases: ClassType
The dataclasses class type.
Source code in xsdata/formats/dataclass/compat.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
any_element
property
Return the generic any element class.
derived_element
property
Return the generic derived element class.
is_model(obj)
Return whether the obj is a dataclass model.
Source code in xsdata/formats/dataclass/compat.py
161 162 163 |
|
verify_model(obj)
Validate whether the obj is a dataclass model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | Any | The input object to validate. | required |
Raises:
Type | Description |
---|---|
XmlContextError | If it's not a dataclass model. |
Source code in xsdata/formats/dataclass/compat.py
165 166 167 168 169 170 171 172 173 174 175 |
|
get_fields(obj)
Return a dataclass fields iterator.
Source code in xsdata/formats/dataclass/compat.py
177 178 179 |
|
default_value(field, default=None)
Return the default value or factory of the given model field.
Source code in xsdata/formats/dataclass/compat.py
181 182 183 184 185 186 187 188 189 |
|
default_choice_value(choice)
Return the default value or factory of the given model field choice.
Source code in xsdata/formats/dataclass/compat.py
191 192 193 194 195 196 197 |
|