Skip to content

rename_duplicate_attributes

xsdata.codegen.handlers.rename_duplicate_attributes

RenameDuplicateAttributes

Bases: HandlerInterface

Resolve attr name conflicts defined in the class.

Source code in xsdata/codegen/handlers/rename_duplicate_attributes.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class RenameDuplicateAttributes(HandlerInterface):
    """Resolve attr name conflicts defined in the class."""

    __slots__ = ()

    def process(self, target: Class):
        """Detect and resolve naming conflicts.

        Args:
            target: The target class instance
        """
        grouped = group_by(target.attrs, key=self._attr_unique_slug)
        for items in grouped.values():
            total = len(items)
            if total == 2 and not items[0].is_enumeration:
                ClassUtils.rename_attribute_by_preference(*items)
            elif total > 1:
                ClassUtils.rename_attributes_by_index(target.attrs, items)

    @staticmethod
    def _attr_unique_slug(attr: Attr) -> str:
        return attr.slug or DEFAULT_ATTR_NAME

process(target)

Detect and resolve naming conflicts.

Parameters:

Name Type Description Default
target Class

The target class instance

required
Source code in xsdata/codegen/handlers/rename_duplicate_attributes.py
13
14
15
16
17
18
19
20
21
22
23
24
25
def process(self, target: Class):
    """Detect and resolve naming conflicts.

    Args:
        target: The target class instance
    """
    grouped = group_by(target.attrs, key=self._attr_unique_slug)
    for items in grouped.values():
        total = len(items)
        if total == 2 and not items[0].is_enumeration:
            ClassUtils.rename_attribute_by_preference(*items)
        elif total > 1:
            ClassUtils.rename_attributes_by_index(target.attrs, items)