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
-
78
69
class Context (dict ):
79
70
"""
80
71
The context object that maps all documented identifiers
@@ -89,6 +80,13 @@ class Context(dict):
89
80
"""
90
81
__pdoc__ ['Context.__init__' ] = False
91
82
83
+ def __init__ (self , * args , ** kwargs ):
84
+ super ().__init__ (* args , ** kwargs )
85
+ # A surrogate so that the check in Module._link_inheritance()
86
+ # "__pdoc__-overriden key {!r} does not exist" can see the object
87
+ # (and not warn).
88
+ self .blacklisted = getattr (args [0 ], 'blacklisted' , set ()) if args else set ()
89
+
92
90
93
91
_global_context = Context ()
94
92
@@ -658,6 +656,8 @@ def __init__(self, module: Union[ModuleType, str], *, docfilter: Callable[[Doc],
658
656
A lookup table for ALL doc objects of all modules that share this context,
659
657
mainly used in `Module.find_ident()`.
660
658
"""
659
+ assert isinstance (self ._context , Context ), \
660
+ 'pdoc.Module(context=) should be a pdoc.Context instance'
661
661
662
662
self .supermodule = supermodule
663
663
"""
@@ -675,8 +675,8 @@ def __init__(self, module: Union[ModuleType, str], *, docfilter: Callable[[Doc],
675
675
var_docstrings , _ = _pep224_docstrings (self )
676
676
677
677
# Populate self.doc with this module's public members
678
+ public_objs = []
678
679
if hasattr (self .obj , '__all__' ):
679
- public_objs = []
680
680
for name in self .obj .__all__ :
681
681
try :
682
682
obj = getattr (self .obj , name )
@@ -691,20 +691,25 @@ def is_from_this_module(obj):
691
691
mod = inspect .getmodule (inspect .unwrap (obj ))
692
692
return mod is None or mod .__name__ == self .obj .__name__
693
693
694
- public_objs = [(name , (_BLACKLISTED_DUMMY
695
- if _is_blacklisted (name , self ) else
696
- inspect .unwrap (obj )))
697
- for name , obj in inspect .getmembers (self .obj )
698
- if ((_is_public (name ) or _is_whitelisted (name , self )) and
699
- (_is_blacklisted (name , self ) or # skips unwrapping that follows
700
- is_from_this_module (obj ) or name in var_docstrings ))]
694
+ for name , obj in inspect .getmembers (self .obj ):
695
+ if ((_is_public (name ) or
696
+ _is_whitelisted (name , self )) and
697
+ (_is_blacklisted (name , self ) or # skips unwrapping that follows
698
+ is_from_this_module (obj ) or
699
+ name in var_docstrings )):
700
+
701
+ if _is_blacklisted (name , self ):
702
+ self ._context .blacklisted .add (f'{ self .refname } .{ name } ' )
703
+ continue
704
+
705
+ obj = inspect .unwrap (obj )
706
+ public_objs .append ((name , obj ))
707
+
701
708
index = list (self .obj .__dict__ ).index
702
709
public_objs .sort (key = lambda i : index (i [0 ]))
703
710
704
711
for name , obj in public_objs :
705
- if obj is _BLACKLISTED_DUMMY :
706
- self .doc [name ] = Variable (name , self , 'dummy' , obj = obj )
707
- elif _is_function (obj ):
712
+ if _is_function (obj ):
708
713
self .doc [name ] = Function (name , self , obj )
709
714
elif inspect .isclass (obj ):
710
715
self .doc [name ] = Class (name , self , obj )
@@ -819,7 +824,9 @@ def _link_inheritance(self):
819
824
continue
820
825
821
826
if (not name .endswith ('.__init__' ) and
822
- name not in self .doc and refname not in self ._context ):
827
+ name not in self .doc and
828
+ refname not in self ._context and
829
+ refname not in self ._context .blacklisted ):
823
830
warn (f'__pdoc__-overriden key { name !r} does not exist '
824
831
f'in module { self .name !r} ' )
825
832
@@ -1018,14 +1025,21 @@ def __init__(self, name: str, module: Module, obj, *, docstring: str = None):
1018
1025
# Use only own, non-inherited annotations (the rest will be inherited)
1019
1026
annotations = getattr (self .obj , '__annotations__' , {})
1020
1027
1021
- public_objs = [(_name , (_BLACKLISTED_DUMMY
1022
- if _is_blacklisted (_name , self ) else
1023
- inspect .unwrap (obj )))
1024
- for _name , obj in _getmembers_all (self .obj )
1025
- # Filter only *own* members. The rest are inherited
1026
- # in Class._fill_inheritance()
1027
- if (_name in self .obj .__dict__ or _name in annotations )
1028
- and (_is_public (_name ) or _is_whitelisted (_name , self ))]
1028
+ public_objs = []
1029
+ for _name , obj in _getmembers_all (self .obj ):
1030
+ # Filter only *own* members. The rest are inherited
1031
+ # in Class._fill_inheritance()
1032
+ if ((_name in self .obj .__dict__ or
1033
+ _name in annotations ) and
1034
+ (_is_public (_name ) or
1035
+ _is_whitelisted (_name , self ))):
1036
+
1037
+ if _is_blacklisted (_name , self ):
1038
+ self .module ._context .blacklisted .add (f'{ self .refname } .{ _name } ' )
1039
+ continue
1040
+
1041
+ obj = inspect .unwrap (obj )
1042
+ public_objs .append ((_name , obj ))
1029
1043
1030
1044
def definition_order_index (
1031
1045
name ,
@@ -1046,9 +1060,7 @@ def definition_order_index(
1046
1060
1047
1061
# Convert the public Python objects to documentation objects.
1048
1062
for name , obj in public_objs :
1049
- if obj is _BLACKLISTED_DUMMY :
1050
- self .doc [name ] = Variable (name , self .module , 'dummy' , obj = obj , cls = self )
1051
- elif _is_function (obj ):
1063
+ if _is_function (obj ):
1052
1064
self .doc [name ] = Function (
1053
1065
name , self .module , obj , cls = self )
1054
1066
else :
0 commit comments