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

Sort classes by name before renaming #517

Merged
merged 1 commit into from
Jun 5, 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
4 changes: 2 additions & 2 deletions tests/codegen/handlers/test_class_name_conflict.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def test_rename_classes(self, mock_rename_class):

mock_rename_class.assert_has_calls(
[
mock.call(classes[0], False),
mock.call(classes[1], False),
mock.call(classes[0], False),
mock.call(classes[2], False),
mock.call(classes[0], True),
mock.call(classes[1], True),
mock.call(classes[0], True),
mock.call(classes[2], True),
]
)
Expand Down
6 changes: 3 additions & 3 deletions xsdata/codegen/handlers/attribute_default_value.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from operator import attrgetter
from typing import Optional

from xsdata.codegen.mixins import RelativeHandlerInterface
Expand Down Expand Up @@ -85,6 +86,5 @@ def find_enum(self, attr_type: AttrType) -> Optional[Class]:
if attr_type.native:
return None

return self.container.find(
attr_type.qname, condition=lambda x: x.is_enumeration
)
is_enumeration = attrgetter("is_enumeration")
return self.container.find(attr_type.qname, condition=is_enumeration)
2 changes: 1 addition & 1 deletion xsdata/codegen/handlers/class_name_conflict.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def rename_classes(self, classes: List[Class], use_name: bool):
the list.
"""
total_elements = sum(x.is_element for x in classes)
for target in classes:
for target in sorted(classes, key=operator.attrgetter("name")):
if not target.is_element or total_elements > 1:
self.rename_class(target, use_name)

Expand Down