diff options
author | Viktor Haag <Viktor.Haag@D2L.com> | 2019-06-13 21:01:57 +0300 |
---|---|---|
committer | Viktor Haag <Viktor.Haag@D2L.com> | 2019-06-13 21:01:57 +0300 |
commit | 3973e897d18aa0b646e7f2bf9d90aba87b9d3a98 (patch) | |
tree | 4cdde12fdd64f2a9adc6c83403ac694898766720 /sphinx/directives | |
parent | 5b307fcf4f73517e79352b6b6857c35f4f1783ba (diff) |
Explicitly treat ObjectDescription._doc_field_type_map as an instance variable
- Aims to address [issue #6478](https://github.com/sphinx-doc/sphinx/issues/6478)
- Left ObjectDescription._doc_field_type_map declaration alone and in place in
case there are other factors at play that require it declared on the class.
- In ObjectDescription constructor, explicitly set _doc_field_type_map's value
as an instance variable.
- This presumably needs to be built with every instantiation of an
ObjectDescription or inheriting class, so we're not attempting to "define it
once on a class and then use it"... that approach seems much harder to reason
about and get correctly done (as was maybe demonstrated by the refactoring
that lead to this problem in the linked-to issue).
- Runs through the test suite clean locally except for an unrelated single test
failure on an image_converter test, which also failed on the base branch
before my changes here.
Diffstat (limited to 'sphinx/directives')
-rw-r--r-- | sphinx/directives/__init__.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/sphinx/directives/__init__.py b/sphinx/directives/__init__.py index 40f838c48..68a27090f 100644 --- a/sphinx/directives/__init__.py +++ b/sphinx/directives/__init__.py @@ -70,18 +70,23 @@ 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): + 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): + 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: - for name in field.names: - self._doc_field_type_map[name] = (field, False) - - 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): |