diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 669a90031..76f956472 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: hooks: - id: reorder-python-imports - repo: https://github.com/ambv/black - rev: 22.6.0 + rev: 22.8.0 hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 diff --git a/tests/codegen/handlers/test_flatten_attribute_groups.py b/tests/codegen/handlers/test_flatten_attribute_groups.py index 1655f5049..3a4f66f8a 100644 --- a/tests/codegen/handlers/test_flatten_attribute_groups.py +++ b/tests/codegen/handlers/test_flatten_attribute_groups.py @@ -47,7 +47,7 @@ def test_process(self, mock_process_attribute, mock_is_group): @mock.patch.object(ClassUtils, "copy_group_attributes") def test_process_attribute_with_group(self, mock_copy_group_attributes): complex_bar = ClassFactory.create(qname="bar", tag=Tag.COMPLEX_TYPE) - group_bar = ClassFactory.create(qname="bar", tag=Tag.GROUP) + group_bar = ClassFactory.create(qname="bar", tag=Tag.ATTRIBUTE_GROUP) group_attr = AttrFactory.attribute_group(name="bar") target = ClassFactory.create() target.attrs.append(group_attr) @@ -80,7 +80,7 @@ def test_process_attribute_with_attribute_group(self, mock_copy_group_attributes def test_process_attribute_with_circular_reference(self): group_attr = AttrFactory.attribute_group(name="bar") - target = ClassFactory.create(qname="bar", tag=Tag.GROUP) + target = ClassFactory.create(qname="bar", tag=Tag.ATTRIBUTE_GROUP) target.attrs.append(group_attr) target.status = Status.FLATTENING diff --git a/xsdata/codegen/handlers/flatten_attribute_groups.py b/xsdata/codegen/handlers/flatten_attribute_groups.py index e2e23787a..67f2fa6ac 100644 --- a/xsdata/codegen/handlers/flatten_attribute_groups.py +++ b/xsdata/codegen/handlers/flatten_attribute_groups.py @@ -1,13 +1,12 @@ from xsdata.codegen.mixins import RelativeHandlerInterface from xsdata.codegen.models import Attr from xsdata.codegen.models import Class -from xsdata.codegen.models import is_group from xsdata.codegen.utils import ClassUtils from xsdata.exceptions import AnalyzerValueError class FlattenAttributeGroups(RelativeHandlerInterface): - """Replace attribute groups with the source class attributes.""" + """Replace groups and attGroups with the source class attributes.""" __slots__ = () @@ -36,7 +35,7 @@ def process_attribute(self, target: Class, attr: Attr): :raises AnalyzerValueError: if source class is not found. """ qname = attr.types[0].qname # group attributes have one type only. - source = self.container.find(qname, condition=is_group) + source = self.container.find(qname, condition=lambda x: x.tag == attr.tag) if not source: raise AnalyzerValueError(f"Group attribute not found: `{qname}`")