self.type = type
def __repr__(self):
- if isinstance(self.type, type) and not isinstance(self.type, GenericAlias):
+ if isinstance(self.type, type):
type_name = self.type.__name__
else:
# typing objects, e.g. List[int]
def is_dataclass(obj):
"""Returns True if obj is a dataclass or an instance of a
dataclass."""
- cls = obj if isinstance(obj, type) and not isinstance(obj, GenericAlias) else type(obj)
+ cls = obj if isinstance(obj, type) else type(obj)
return hasattr(cls, _FIELDS)
return get_origin(cls) in {Union, types.UnionType}
def _is_valid_dispatch_type(cls):
- if isinstance(cls, type) and not isinstance(cls, GenericAlias):
+ if isinstance(cls, type):
return True
from typing import get_args
return (_is_union_type(cls) and
- all(isinstance(arg, type) and not isinstance(arg, GenericAlias)
- for arg in get_args(cls)))
+ all(isinstance(arg, type) for arg in get_args(cls)))
def register(cls, func=None):
"""generic_func.register(cls, func) -> func
import sysconfig
import time
import tokenize
-import types
import urllib.parse
import warnings
from collections import deque
normdirs.append(normdir)
return dirs
-def _isclass(object):
- return inspect.isclass(object) and not isinstance(object, types.GenericAlias)
-
def _findclass(func):
cls = sys.modules.get(func.__module__)
if cls is None:
return None
for name in func.__qualname__.split('.')[:-1]:
cls = getattr(cls, name)
- if not _isclass(cls):
+ if not inspect.isclass(cls):
return None
return cls
if inspect.ismethod(obj):
name = obj.__func__.__name__
self = obj.__self__
- if (_isclass(self) and
+ if (inspect.isclass(self) and
getattr(getattr(self, name, None), '__func__') is obj.__func__):
# classmethod
cls = self
elif inspect.isbuiltin(obj):
name = obj.__name__
self = obj.__self__
- if (_isclass(self) and
+ if (inspect.isclass(self) and
self.__qualname__ + '.' + name == obj.__qualname__):
# classmethod
cls = self
def isdata(object):
"""Check if an object is of a type that probably means it's data."""
- return not (inspect.ismodule(object) or _isclass(object) or
+ return not (inspect.ismodule(object) or inspect.isclass(object) or
inspect.isroutine(object) or inspect.isframe(object) or
inspect.istraceback(object) or inspect.iscode(object))
# by lacking a __name__ attribute) and an instance.
try:
if inspect.ismodule(object): return self.docmodule(*args)
- if _isclass(object): return self.docclass(*args)
+ if inspect.isclass(object): return self.docclass(*args)
if inspect.isroutine(object): return self.docroutine(*args)
except AttributeError:
pass
modules = inspect.getmembers(object, inspect.ismodule)
classes, cdict = [], {}
- for key, value in inspect.getmembers(object, _isclass):
+ for key, value in inspect.getmembers(object, inspect.isclass):
# if __all__ exists, believe it. Otherwise use old heuristic.
if (all is not None or
(inspect.getmodule(value) or object) is object):
result = result + self.section('DESCRIPTION', desc)
classes = []
- for key, value in inspect.getmembers(object, _isclass):
+ for key, value in inspect.getmembers(object, inspect.isclass):
# if __all__ exists, believe it. Otherwise use old heuristic.
if (all is not None
or (inspect.getmodule(value) or object) is object):
return 'member descriptor %s.%s.%s' % (
thing.__objclass__.__module__, thing.__objclass__.__name__,
thing.__name__)
- if _isclass(thing):
+ if inspect.isclass(thing):
return 'class ' + thing.__name__
if inspect.isfunction(thing):
return 'function ' + thing.__name__
desc += ' in module ' + module.__name__
if not (inspect.ismodule(object) or
- _isclass(object) or
+ inspect.isclass(object) or
inspect.isroutine(object) or
inspect.isdatadescriptor(object) or
_getdoc(object)):