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

Explicitly treat ObjectDescription._doc_field_type_map as an instance variable #6482

Merged
Changes from 3 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
27 changes: 17 additions & 10 deletions sphinx/directives/__init__.py
Expand Up @@ -70,18 +70,25 @@ class ObjectDescription(SphinxDirective):
# Warning: this might be removed in future version. Don't touch this from extensions.
_doc_field_type_map = {} # type: Dict[str, Tuple[Field, bool]]

def _process_type_map(self, typelist):
# type: (List[Field]) -> Dict[str, Tuple[Field, bool]]
typemap = {}
for field in typelist:
for name in field.names:
typemap[name] = (field, False)
if field.is_typed:
typed_field = cast(TypedField, field)
for name in typed_field.typenames:
typemap[name] = (field, True)
return typemap

def __init__(self, *args, **kwargs):
# type: (*Any, **Any) -> None
SphinxDirective.__init__(self, *args, **kwargs)
self._doc_field_type_map = self._process_type_map(self.doc_field_types)

def get_field_type_map(self):
# type: () -> Dict[str, Tuple[Field, bool]]
if self._doc_field_type_map == {}:
for field in self.doc_field_types:
ViktorHaag marked this conversation as resolved.
Show resolved Hide resolved
for name in field.names:
self._doc_field_type_map[name] = (field, False)

ViktorHaag marked this conversation as resolved.
Show resolved Hide resolved
if field.is_typed:
typed_field = cast(TypedField, field)
for name in typed_field.typenames:
self._doc_field_type_map[name] = (field, True)

return self._doc_field_type_map

def get_signatures(self):
Expand Down