66
66
tpl_lookup .directories .insert (0 , path .join (os .getenv ("XDG_CONFIG_HOME" , '' ), "pdoc" ))
67
67
68
68
69
+ # A surrogate so that the check in Module._link_inheritance()
70
+ # "__pdoc__-overriden key {!r} does not exist" can pick the object up
71
+ # (and not warn).
72
+ # If you know how to keep the warning, but skip the object creation
73
+ # altogether, please make it happen!
74
+ class _BLACKLISTED_DUMMY :
75
+ pass
76
+
77
+
69
78
class Context (dict ):
70
79
"""
71
80
The context object that maps all documented identifiers
@@ -90,7 +99,9 @@ def reset():
90
99
_global_context .clear ()
91
100
92
101
# Clear LRU caches
93
- for func in (_get_type_hints ,):
102
+ for func in (_get_type_hints ,
103
+ _is_blacklisted ,
104
+ _is_whitelisted ):
94
105
func .cache_clear ()
95
106
for cls in (Doc , Module , Class , Function , Variable , External ):
96
107
for _ , method in inspect .getmembers (cls ):
@@ -318,6 +329,7 @@ def _pep224_docstrings(doc_obj: Union['Module', 'Class'], *,
318
329
return vars , instance_vars
319
330
320
331
332
+ @lru_cache ()
321
333
def _is_whitelisted (name : str , doc_obj : Union ['Module' , 'Class' ]):
322
334
"""
323
335
Returns `True` if `name` (relative or absolute refname) is
@@ -333,6 +345,7 @@ def _is_whitelisted(name: str, doc_obj: Union['Module', 'Class']):
333
345
return False
334
346
335
347
348
+ @lru_cache ()
336
349
def _is_blacklisted (name : str , doc_obj : Union ['Module' , 'Class' ]):
337
350
"""
338
351
Returns `True` if `name` (relative or absolute refname) is
@@ -624,24 +637,32 @@ def __init__(self, module: Union[ModuleType, str], *, docfilter: Callable[[Doc],
624
637
public_objs = []
625
638
for name in self .obj .__all__ :
626
639
try :
627
- public_objs . append (( name , getattr (self .obj , name )) )
640
+ obj = getattr (self .obj , name )
628
641
except AttributeError :
629
642
warn ("Module {!r} doesn't contain identifier `{}` "
630
643
"exported in `__all__`" .format (self .module , name ))
644
+ if not _is_blacklisted (name , self ):
645
+ obj = inspect .unwrap (obj )
646
+ public_objs .append ((name , obj ))
631
647
else :
632
648
def is_from_this_module (obj ):
633
649
mod = inspect .getmodule (inspect .unwrap (obj ))
634
650
return mod is None or mod .__name__ == self .obj .__name__
635
651
636
- public_objs = [(name , inspect .unwrap (obj ))
652
+ public_objs = [(name , (_BLACKLISTED_DUMMY
653
+ if _is_blacklisted (name , self ) else
654
+ inspect .unwrap (obj )))
637
655
for name , obj in inspect .getmembers (self .obj )
638
656
if ((_is_public (name ) or _is_whitelisted (name , self )) and
639
- (is_from_this_module (obj ) or name in var_docstrings ))]
657
+ (_is_blacklisted (name , self ) or # skips unwrapping that follows
658
+ is_from_this_module (obj ) or name in var_docstrings ))]
640
659
index = list (self .obj .__dict__ ).index
641
660
public_objs .sort (key = lambda i : index (i [0 ]))
642
661
643
662
for name , obj in public_objs :
644
- if _is_function (obj ):
663
+ if obj is _BLACKLISTED_DUMMY :
664
+ self .doc [name ] = Variable (name , self , 'dummy' , obj = obj )
665
+ elif _is_function (obj ):
645
666
self .doc [name ] = Function (name , self , obj )
646
667
elif inspect .isclass (obj ):
647
668
self .doc [name ] = Class (name , self , obj )
@@ -955,7 +976,9 @@ def __init__(self, name, module, obj, *, docstring=None):
955
976
# Use only own, non-inherited annotations (the rest will be inherited)
956
977
annotations = getattr (self .obj , '__annotations__' , {})
957
978
958
- public_objs = [(_name , inspect .unwrap (obj ))
979
+ public_objs = [(_name , (_BLACKLISTED_DUMMY
980
+ if _is_blacklisted (_name , self ) else
981
+ inspect .unwrap (obj )))
959
982
for _name , obj in _getmembers_all (self .obj )
960
983
# Filter only *own* members. The rest are inherited
961
984
# in Class._fill_inheritance()
@@ -981,7 +1004,9 @@ def definition_order_index(
981
1004
982
1005
# Convert the public Python objects to documentation objects.
983
1006
for name , obj in public_objs :
984
- if _is_function (obj ):
1007
+ if obj is _BLACKLISTED_DUMMY :
1008
+ self .doc [name ] = Variable (name , self .module , 'dummy' , obj = obj , cls = self )
1009
+ elif _is_function (obj ):
985
1010
self .doc [name ] = Function (
986
1011
name , self .module , obj , cls = self )
987
1012
else :
0 commit comments