Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #8372: autodoc: autoclass directive became slower than Sphinx-3.2 #8387

Merged
merged 1 commit into from Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -16,6 +16,7 @@ Features added
Bugs fixed
----------

* #8372: autodoc: autoclass directive became slower than Sphinx-3.2
* #8364: C, properly initialize attributes in empty symbols.

Testing
Expand Down
3 changes: 3 additions & 0 deletions sphinx/ext/autodoc/__init__.py
Expand Up @@ -1503,6 +1503,9 @@ def get_overloaded_signatures(self) -> List[Signature]:
qualname = '.'.join([cls.__qualname__, self._signature_method_name])
if qualname in analyzer.overloads:
return analyzer.overloads.get(qualname)
elif qualname in analyzer.tagorder:
# the constructor is defined in the class, but not overrided.
return []
except PycodeError:
pass

Expand Down
13 changes: 7 additions & 6 deletions sphinx/pycode/__init__.py
Expand Up @@ -150,9 +150,13 @@ def __init__(self, source: IO, modname: str, srcname: str, decoded: bool = False
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()
Expand All @@ -169,21 +173,18 @@ def parse(self) -> None:
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
Expand Down