validate_attributes_overrides
xsdata.codegen.handlers.validate_attributes_overrides
ValidateAttributesOverrides
Bases: RelativeHandlerInterface
Validate override and restricted attributes.
Source code in xsdata/codegen/handlers/validate_attributes_overrides.py
11 12 13 14 15 16 17 18 19 20 21 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 106 107 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 144 145 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 198 199 |
|
process(target)
Process entrypoint for classes.
- Validate override attrs
- Add restricted attrs
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target | Class | The target class instance | required |
Source code in xsdata/codegen/handlers/validate_attributes_overrides.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
prohibit_parent_attrs(target, explicit_attrs, base_attrs_map)
classmethod
Prepend prohibited parent attrs to the target class.
Prepend the parent prohibited attrs and reset their types and default values in order to avoid conflicts later.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target | Class | The target class instance | required |
explicit_attrs | set[str] | The list of explicit attrs in the class | required |
base_attrs_map | dict[str, list[Attr]] | A mapping of qualified names to lists of parent attrs | required |
Source code in xsdata/codegen/handlers/validate_attributes_overrides.py
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 |
|
validate_attrs(target, base_attrs_map)
classmethod
Validate overriding attrs.
Cases
- Overriding attr, either remove it or update parent attr
- Duplicate names, resolve conflicts
- Remove prohibited attrs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target | Class | The target class instance | required |
base_attrs_map | dict[str, list[Attr]] | A mapping of qualified names to lists of parent attrs | required |
Source code in xsdata/codegen/handlers/validate_attributes_overrides.py
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 |
|
overrides(a, b)
classmethod
Override attrs must belong to the same xml type and namespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a | Attr | The first attr | required |
b | Attr | The second attr | required |
Returns:
Type | Description |
---|---|
bool | The bool result. |
Source code in xsdata/codegen/handlers/validate_attributes_overrides.py
89 90 91 92 93 94 95 96 97 98 99 100 |
|
base_attrs_map(target)
Create a mapping of qualified names to lists of parent attrs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target | Class | The target class instance | required |
Returns:
Type | Description |
---|---|
dict[str, list[Attr]] | A mapping of qualified names to lists of parent attrs. |
Source code in xsdata/codegen/handlers/validate_attributes_overrides.py
102 103 104 105 106 107 108 109 110 111 112 |
|
validate_override(target, child_attr, parent_attr)
classmethod
Validate the override will not break mypy type checking.
- Ignore wildcard attrs.
- If child is a list and parent isn't convert parent to list
- If restrictions are the same we can safely remove override attr
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target | Class | The target class instance | required |
child_attr | Attr | The child attr | required |
parent_attr | Attr | The parent attr | required |
Source code in xsdata/codegen/handlers/validate_attributes_overrides.py
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 144 145 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 |
|
remove_attribute(target, attr)
classmethod
Safely remove attr.
The search is done with the reference id for safety, of removing attrs with same name. If the attr has a forward reference, the inner class will also be removed if it's unused!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target | Class | The target class instance | required |
attr | Attr | The attr to remove | required |
Source code in xsdata/codegen/handlers/validate_attributes_overrides.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
resolve_conflict(child_attr, parent_attr)
classmethod
Rename the child or parent attr.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
child_attr | Attr | The child attr instance | required |
parent_attr | Attr | The parent attr instance | required |
Source code in xsdata/codegen/handlers/validate_attributes_overrides.py
191 192 193 194 195 196 197 198 199 |
|