Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude abstract elements from class fields #627

Merged
merged 1 commit into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/codegen/handlers/test_attribute_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,22 @@ def test_process_dependency_type_with_complex_type(
self.processor.process_dependency_type(target, attr, attr_type)
self.assertTrue(attr.restrictions.nillable)

@mock.patch.object(AttributeTypeHandler, "find_dependency")
def test_process_dependency_type_with_abstract_type_type(
self, mock_find_dependency
):
complex_type = ClassFactory.create(tag=Tag.ELEMENT, abstract=True)
mock_find_dependency.return_value = complex_type

attr = AttrFactory.create()
attr_type = attr.types[0]
target = ClassFactory.create()
target.attrs.append(attr)

self.assertEqual(1, len(target.attrs))
self.processor.process_dependency_type(target, attr, attr_type)
self.assertEqual(0, len(target.attrs))

@mock.patch.object(AttributeTypeHandler, "update_restrictions")
@mock.patch.object(AttributeTypeHandler, "copy_attribute_properties")
def test_process_inner_type_with_simple_type(
Expand Down
4 changes: 4 additions & 0 deletions xsdata/codegen/handlers/attribute_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ def process_dependency_type(self, target: Class, attr: Attr, attr_type: AttrType
x.restrictions.format for x in source.attrs if x.restrictions.format
)
attr_type.reference = id(source)
elif source.is_element and source.abstract:
# Substitution groups with abstract elements are used like
# placeholders and shouldn't be added as standalone fields.
target.attrs.remove(attr)
else:
if source.nillable:
attr.restrictions.nillable = True
Expand Down