Beispiel #1
0
 def check_subclass(arg_name,
                    type_,
                    template_types,
                    prim_name,
                    addition_error_info=None):
     """Checks whether some type is subclass of another type"""
     if not isinstance(template_types, Iterable):
         template_types = (template_types, )
     hit = False
     for template_type in template_types:
         if isinstance(template_type, mstype.Type):
             if mstype.issubclass_(type_, template_type):
                 hit = True
                 break
         elif type_ is template_type:
             hit = True
             break
     if not hit:
         if addition_error_info is None:
             addition_error_info = ''
         type_str = (type(type_).__name__ if isinstance(
             type_, (tuple, list)) else "") + str(type_)
         raise TypeError(
             f'For \'{prim_name}\', the type of `{arg_name}` should be subclass'
             f' of {", ".join((str(x) for x in template_types))}, but got {type_str}.'
             f' {addition_error_info}')
Beispiel #2
0
def check_type_same(x_type, base_type):
    """Check x_type is same as base_type."""
    if mstype.issubclass_(x_type, base_type):
        return True
    return False
Beispiel #3
0
def check_type_same(x_type, base_type):
    """Check x_type is same as base_type."""
    if mstype.issubclass_(x_type, base_type):
        return True
    raise TypeError(f"The arg 'x' should be a {base_type}, but got {x_type}.")
def check_type_same(x_type, base_type):
    """Check x_type is same as base_type."""
    return mstype.issubclass_(x_type, base_type)