Commits

solos committed 0ce14db Merge

合并 birkenfeld/sphinx 到 default

Comments (0)

Files changed (2)

sphinx/ext/napoleon/__init__.py

                 qualname = getattr(obj, '__qualname__', '')
                 cls_path, _, _ = qualname.rpartition('.')
                 if cls_path:
-                    import importlib
-                    import functools
+                    try:
+                        if '.' in cls_path:
+                            import importlib
+                            import functools
 
-                    mod = importlib.import_module(obj.__module__)
-                    cls = functools.reduce(getattr, cls_path.split('.'), mod)
-                    cls_is_owner = (cls and hasattr(cls, name) and
-                                    name in cls.__dict__)
+                            mod = importlib.import_module(obj.__module__)
+                            mod_path = cls_path.split('.')
+                            cls = functools.reduce(getattr, mod_path, mod)
+                        else:
+                            cls = obj.__globals__[cls_path]
+                    except:
+                        cls_is_owner = False
+                    else:
+                        cls_is_owner = (cls and hasattr(cls, name) and
+                                        name in cls.__dict__)
                 else:
                     cls_is_owner = False
             else:

tests/test_napoleon.py

     from unittest.mock import Mock
 except ImportError:
     from mock import Mock
+from collections import namedtuple
 from sphinx.application import Sphinx
 from sphinx.ext.napoleon import (_process_docstring, _skip_member, Config,
                                  setup)
     def __special_undoc__(self):
         pass
 
+SampleNamedTuple = namedtuple('SampleNamedTuple', 'user_id block_type def_id')
+
 
 class ProcessDocstringTest(TestCase):
     def test_modify_in_place(self):
         self.assertEqual(skip, _skip_member(app, what, member, obj, skip,
                                             Mock()))
 
+    def test_namedtuple(self):
+        self.assertSkip('class', '_asdict',
+                        SampleNamedTuple._asdict, False,
+                        'napoleon_include_private_with_doc')
+
     def test_class_private_doc(self):
         self.assertSkip('class', '_private_doc',
                         SampleClass._private_doc, False,