typedargs/typeinfo.py
def get_type(self, type_name):
        """Return the type object corresponding to a type name.

        If type_name is not found, this triggers the loading of
        external types until a matching type is found or until there
        are no more external type sources.
        """

        type_name = self._canonicalize_type(type_name)

        # Add basic transformations on common abbreviations
        if str(type_name) == 'int':
            type_name = 'integer'
        elif str(type_name) == 'str':
            type_name = 'string'
        elif str(type_name) == 'dict':
            type_name = 'basic_dict'

        if self.is_known_type(type_name):
            return self.known_types[type_name]

        base_type, is_complex, subtypes = self.split_type(type_name)
        if is_complex and base_type in self.type_factories:
            self.instantiate_type(type_name, base_type, subtypes)
            return self.known_types[type_name]

        # If we're here, this is a type that we don't know anything about, so go find it.
        i = 0
        for i, (source, name) in enumerate(self._lazy_type_sources):
            if isinstance(source, str):
                import pkg_resources

                for entry in pkg_resources.iter_entry_points(source):
                    try:
                        mod = entry.load()
                        type_system.load_type_module(mod)
                    except:  #pylint:disable=W0702; We want to catch everything here since we don't want external plugins breaking us
                        fail_info = ("Entry point group: %s, name: %s" % (source, entry.name), sys.exc_info)
                        logging.exception("Error loading external type source from entry point, group: %s, name: %s", source, entry.name)
                        self.failed_sources.append(fail_info)
            else:
                try:
                    source(self)
                except:  #pylint:disable=W0702; We want to catch everything here since we don't want external plugins breaking us
                    fail_info = ("source: %s" % name, sys.exc_info)
                    logging.exception("Error loading external type source, source: %s", source)
                    self.failed_sources.append(fail_info)

            # Only load as many external sources as we need to resolve this type_name
            if self.is_known_type(type_name) or (is_complex and base_type in self.type_factories):
                break

        self._lazy_type_sources = self._lazy_type_sources[i:]

        # If we've loaded everything and we still can't find it then there's a configuration error somewhere
        if not (self.is_known_type(type_name) or (is_complex and base_type in self.type_factories)):
            raise ArgumentError("get_type called on unknown type", type=type_name, failed_external_sources=[x[0] for x in self.failed_sources])

        return self.get_type(type_name)
def get_type(self, type_name):
        type_name = self._canonicalize_type(type_name)

        # Add basic transformations on common abbreviations
        if str(type_name) == 'int':
            type_name = 'integer'
        elif str(type_name) == 'str':
            type_name = 'string'
        elif str(type_name) == 'dict':
            type_name = 'basic_dict'

        if self.is_known_type(type_name):
            return self.known_types[type_name]

        base_type, is_complex, subtypes = self.split_type(type_name)
        if is_complex and base_type in self.type_factories:
            self.instantiate_type(type_name, base_type, subtypes)
            return self.known_types[type_name]

        # If we're here, this is a type that we don't know anything about, so go find it.
        i = 0
        for i, (source, name) in enumerate(self._lazy_type_sources):
            if isinstance(source, str):
                import pkg_resources

                for entry in pkg_resources.iter_entry_points(source):
                    try:
                        mod = entry.load()
                        type_system.load_type_module(mod)
                    except:  #pylint:disable=W0702; We want to catch everything here since we don't want external plugins breaking us
                        fail_info = ("Entry point group: %s, name: %s" % (source, entry.name), sys.exc_info)
                        logging.exception("Error loading external type source from entry point, group: %s, name: %s", source, entry.name)
                        self.failed_sources.append(fail_info)
            else:
                try:
                    source(self)
                except:  #pylint:disable=W0702; We want to catch everything here since we don't want external plugins breaking us
                    fail_info = ("source: %s" % name, sys.exc_info)
                    logging.exception("Error loading external type source, source: %s", source)
                    self.failed_sources.append(fail_info)

            # Only load as many external sources as we need to resolve this type_name
            if self.is_known_type(type_name) or (is_complex and base_type in self.type_factories):
                break

        self._lazy_type_sources = self._lazy_type_sources[i:]

        # If we've loaded everything and we still can't find it then there's a configuration error somewhere
        if not (self.is_known_type(type_name) or (is_complex and base_type in self.type_factories)):
            raise ArgumentError("get_type called on unknown type", type=type_name, failed_external_sources=[x[0] for x in self.failed_sources])

        return self.get_type(type_name)
def get_type ( self , type_name ) : type_name = self . _canonicalize_type ( type_name ) # Add basic transformations on common abbreviations if str ( type_name ) == 'int' : type_name = 'integer' elif str ( type_name ) == 'str' : type_name = 'string' elif str ( type_name ) == 'dict' : type_name = 'basic_dict' if self . is_known_type ( type_name ) : return self . known_types [ type_name ] base_type , is_complex , subtypes = self . split_type ( type_name ) if is_complex and base_type in self . type_factories : self . instantiate_type ( type_name , base_type , subtypes ) return self . known_types [ type_name ] # If we're here, this is a type that we don't know anything about, so go find it. i = 0 for i , ( source , name ) in enumerate ( self . _lazy_type_sources ) : if isinstance ( source , str ) : import pkg_resources for entry in pkg_resources . iter_entry_points ( source ) : try : mod = entry . load ( ) type_system . load_type_module ( mod ) except : #pylint:disable=W0702; We want to catch everything here since we don't want external plugins breaking us fail_info = ( "Entry point group: %s, name: %s" % ( source , entry . name ) , sys . exc_info ) logging . exception ( "Error loading external type source from entry point, group: %s, name: %s" , source , entry . name ) self . failed_sources . append ( fail_info ) else : try : source ( self ) except : #pylint:disable=W0702; We want to catch everything here since we don't want external plugins breaking us fail_info = ( "source: %s" % name , sys . exc_info ) logging . exception ( "Error loading external type source, source: %s" , source ) self . failed_sources . append ( fail_info ) # Only load as many external sources as we need to resolve this type_name if self . is_known_type ( type_name ) or ( is_complex and base_type in self . type_factories ) : break self . _lazy_type_sources = self . _lazy_type_sources [ i : ] # If we've loaded everything and we still can't find it then there's a configuration error somewhere if not ( self . is_known_type ( type_name ) or ( is_complex and base_type in self . type_factories ) ) : raise ArgumentError ( "get_type called on unknown type" , type = type_name , failed_external_sources = [ x [ 0 ] for x in self . failed_sources ] ) return self . get_type ( type_name )
Return the type object corresponding to a type name.

        If type_name is not found, this triggers the loading of
        external types until a matching type is found or until there
        are no more external type sources.
Return the type object corresponding to a type name .