@@ -165,7 +165,7 @@ def _split_list(s, predicate):
165165 no .append (x )
166166 return yes , no
167167
168- def visiblename (name , all = None ):
168+ def visiblename (name , all = None , obj = None ):
169169 """Decide whether to show documentation on a variable."""
170170 # Certain special names are redundant.
171171 _hidden_names = ('__builtins__' , '__doc__' , '__file__' , '__path__' ,
@@ -175,6 +175,9 @@ def visiblename(name, all=None):
175175 if name in _hidden_names : return 0
176176 # Private names are hidden, but special names are displayed.
177177 if name .startswith ('__' ) and name .endswith ('__' ): return 1
178+ # Namedtuples have public fields and methods with a single leading underscore
179+ if name .startswith ('_' ) and hasattr (obj , '_fields' ):
180+ return True
178181 if all is not None :
179182 # only document that which the programmer exported in __all__
180183 return name in all
@@ -642,7 +645,7 @@ def docmodule(self, object, name=None, mod=None, *ignored):
642645 # if __all__ exists, believe it. Otherwise use old heuristic.
643646 if (all is not None or
644647 (inspect .getmodule (value ) or object ) is object ):
645- if visiblename (key , all ):
648+ if visiblename (key , all , object ):
646649 classes .append ((key , value ))
647650 cdict [key ] = cdict [value ] = '#' + key
648651 for key , value in classes :
@@ -658,13 +661,13 @@ def docmodule(self, object, name=None, mod=None, *ignored):
658661 # if __all__ exists, believe it. Otherwise use old heuristic.
659662 if (all is not None or
660663 inspect .isbuiltin (value ) or inspect .getmodule (value ) is object ):
661- if visiblename (key , all ):
664+ if visiblename (key , all , object ):
662665 funcs .append ((key , value ))
663666 fdict [key ] = '#-' + key
664667 if inspect .isfunction (value ): fdict [value ] = fdict [key ]
665668 data = []
666669 for key , value in inspect .getmembers (object , isdata ):
667- if visiblename (key , all ):
670+ if visiblename (key , all , object ):
668671 data .append ((key , value ))
669672
670673 doc = self .markup (getdoc (object ), self .preformat , fdict , cdict )
@@ -789,7 +792,7 @@ def spilldata(msg, attrs, predicate):
789792
790793 attrs = [(name , kind , cls , value )
791794 for name , kind , cls , value in classify_class_attrs (object )
792- if visiblename (name )]
795+ if visiblename (name , obj = object )]
793796
794797 mdict = {}
795798 for key , kind , homecls , value in attrs :
@@ -1056,18 +1059,18 @@ def docmodule(self, object, name=None, mod=None):
10561059 # if __all__ exists, believe it. Otherwise use old heuristic.
10571060 if (all is not None
10581061 or (inspect .getmodule (value ) or object ) is object ):
1059- if visiblename (key , all ):
1062+ if visiblename (key , all , object ):
10601063 classes .append ((key , value ))
10611064 funcs = []
10621065 for key , value in inspect .getmembers (object , inspect .isroutine ):
10631066 # if __all__ exists, believe it. Otherwise use old heuristic.
10641067 if (all is not None or
10651068 inspect .isbuiltin (value ) or inspect .getmodule (value ) is object ):
1066- if visiblename (key , all ):
1069+ if visiblename (key , all , object ):
10671070 funcs .append ((key , value ))
10681071 data = []
10691072 for key , value in inspect .getmembers (object , isdata ):
1070- if visiblename (key , all ):
1073+ if visiblename (key , all , object ):
10711074 data .append ((key , value ))
10721075
10731076 modpkgs = []
@@ -1206,7 +1209,7 @@ def spilldata(msg, attrs, predicate):
12061209
12071210 attrs = [(name , kind , cls , value )
12081211 for name , kind , cls , value in classify_class_attrs (object )
1209- if visiblename (name )]
1212+ if visiblename (name , obj = object )]
12101213
12111214 while attrs :
12121215 if mro :
0 commit comments