示例#1
0
    def process_dependency_type(self, target: Class, attr: Attr,
                                attr_type: AttrType):
        """
        Process an attributes type that depends on any global type.

        Strategies:
            1. Reset absent or dummy attribute types with a warning
            2. Copy attribute properties from a simple type
            3. Copy format restriction from an enumeration
            4. Set circular flag for the rest
        """

        source = self.find_dependency(attr_type, attr.tag)
        if not source or (not source.attrs and not source.extensions):
            logger.warning("Reset dummy type: %s", attr_type.name)
            use_str = not source or not source.is_complex
            self.reset_attribute_type(attr_type, use_str)
        elif source.is_simple_type:
            self.copy_attribute_properties(source, target, attr, attr_type)
        elif source.is_enumeration:
            attr.restrictions.format = collections.first(
                x.restrictions.format for x in source.attrs
                if x.restrictions.format)
            attr_type.reference = id(source)
        else:
            self.set_circular_flag(source, target, attr_type)
示例#2
0
 def set_circular_flag(self, source: Class, target: Class,
                       attr_type: AttrType):
     """Update circular reference flag."""
     attr_type.reference = id(source)
     attr_type.circular = self.is_circular_dependency(source, target, set())