diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-11-08 16:52:22 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-11-08 17:23:32 +0300 |
commit | e3eec9f0e102d01938b99a2fb925b81678270dfa (patch) | |
tree | be19e02e2d8a114d0d6ebd72c0e91ba94be835d3 /sphinx/pycode/__init__.py | |
parent | 1193d83166b7d889343d5aa0268d6c2e9349e692 (diff) |
Fix #8372: autodoc: autoclass directive became slower than Sphinx-3.2
* The result of ModuleAnalyzer.parse() is not cached
* autodoc tries to search overloaded constructor methods to the root
class even if a definition found
Diffstat (limited to 'sphinx/pycode/__init__.py')
-rw-r--r-- | sphinx/pycode/__init__.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py index 4fef4a394..b7163072f 100644 --- a/sphinx/pycode/__init__.py +++ b/sphinx/pycode/__init__.py @@ -150,9 +150,13 @@ class ModuleAnalyzer: self.overloads = None # type: Dict[str, List[Signature]] self.tagorder = None # type: Dict[str, int] self.tags = None # type: Dict[str, Tuple[str, int, int]] + self._parsed = False def parse(self) -> None: """Parse the source code.""" + if self._parsed: + return None + try: parser = Parser(self.code, self._encoding) parser.parse() @@ -169,21 +173,18 @@ class ModuleAnalyzer: self.overloads = parser.overloads self.tags = parser.definitions self.tagorder = parser.deforders + self._parsed = True except Exception as exc: raise PycodeError('parsing %r failed: %r' % (self.srcname, exc)) from exc def find_attr_docs(self) -> Dict[Tuple[str, str], List[str]]: """Find class and module-level attributes and their documentation.""" - if self.attr_docs is None: - self.parse() - + self.parse() return self.attr_docs def find_tags(self) -> Dict[str, Tuple[str, int, int]]: """Find class, function and method definitions and their location.""" - if self.tags is None: - self.parse() - + self.parse() return self.tags @property |