@@ -69,6 +69,7 @@ class or function within a module or module in a package. If the
6969import sysconfig
7070import time
7171import tokenize
72+ import types
7273import urllib .parse
7374import warnings
7475from collections import deque
@@ -90,21 +91,24 @@ def pathdirs():
9091 normdirs .append (normdir )
9192 return dirs
9293
94+ def _isclass (object ):
95+ return inspect .isclass (object ) and not isinstance (object , types .GenericAlias )
96+
9397def _findclass (func ):
9498 cls = sys .modules .get (func .__module__ )
9599 if cls is None :
96100 return None
97101 for name in func .__qualname__ .split ('.' )[:- 1 ]:
98102 cls = getattr (cls , name )
99- if not inspect . isclass (cls ):
103+ if not _isclass (cls ):
100104 return None
101105 return cls
102106
103107def _finddoc (obj ):
104108 if inspect .ismethod (obj ):
105109 name = obj .__func__ .__name__
106110 self = obj .__self__
107- if (inspect . isclass (self ) and
111+ if (_isclass (self ) and
108112 getattr (getattr (self , name , None ), '__func__' ) is obj .__func__ ):
109113 # classmethod
110114 cls = self
@@ -118,7 +122,7 @@ def _finddoc(obj):
118122 elif inspect .isbuiltin (obj ):
119123 name = obj .__name__
120124 self = obj .__self__
121- if (inspect . isclass (self ) and
125+ if (_isclass (self ) and
122126 self .__qualname__ + '.' + name == obj .__qualname__ ):
123127 # classmethod
124128 cls = self
@@ -205,7 +209,7 @@ def classname(object, modname):
205209
206210def isdata (object ):
207211 """Check if an object is of a type that probably means it's data."""
208- return not (inspect .ismodule (object ) or inspect . isclass (object ) or
212+ return not (inspect .ismodule (object ) or _isclass (object ) or
209213 inspect .isroutine (object ) or inspect .isframe (object ) or
210214 inspect .istraceback (object ) or inspect .iscode (object ))
211215
@@ -470,7 +474,7 @@ def document(self, object, name=None, *args):
470474 # by lacking a __name__ attribute) and an instance.
471475 try :
472476 if inspect .ismodule (object ): return self .docmodule (* args )
473- if inspect . isclass (object ): return self .docclass (* args )
477+ if _isclass (object ): return self .docclass (* args )
474478 if inspect .isroutine (object ): return self .docroutine (* args )
475479 except AttributeError :
476480 pass
@@ -775,7 +779,7 @@ def docmodule(self, object, name=None, mod=None, *ignored):
775779 modules = inspect .getmembers (object , inspect .ismodule )
776780
777781 classes , cdict = [], {}
778- for key , value in inspect .getmembers (object , inspect . isclass ):
782+ for key , value in inspect .getmembers (object , _isclass ):
779783 # if __all__ exists, believe it. Otherwise use old heuristic.
780784 if (all is not None or
781785 (inspect .getmodule (value ) or object ) is object ):
@@ -1217,7 +1221,7 @@ def docmodule(self, object, name=None, mod=None):
12171221 result = result + self .section ('DESCRIPTION' , desc )
12181222
12191223 classes = []
1220- for key , value in inspect .getmembers (object , inspect . isclass ):
1224+ for key , value in inspect .getmembers (object , _isclass ):
12211225 # if __all__ exists, believe it. Otherwise use old heuristic.
12221226 if (all is not None
12231227 or (inspect .getmodule (value ) or object ) is object ):
@@ -1699,7 +1703,7 @@ def describe(thing):
16991703 return 'member descriptor %s.%s.%s' % (
17001704 thing .__objclass__ .__module__ , thing .__objclass__ .__name__ ,
17011705 thing .__name__ )
1702- if inspect . isclass (thing ):
1706+ if _isclass (thing ):
17031707 return 'class ' + thing .__name__
17041708 if inspect .isfunction (thing ):
17051709 return 'function ' + thing .__name__
@@ -1760,7 +1764,7 @@ def render_doc(thing, title='Python Library Documentation: %s', forceload=0,
17601764 desc += ' in module ' + module .__name__
17611765
17621766 if not (inspect .ismodule (object ) or
1763- inspect . isclass (object ) or
1767+ _isclass (object ) or
17641768 inspect .isroutine (object ) or
17651769 inspect .isdatadescriptor (object ) or
17661770 _getdoc (object )):
0 commit comments