diff options
author | Viktor Haag <Viktor.Haag@D2L.com> | 2019-06-18 16:22:25 +0300 |
---|---|---|
committer | Viktor Haag <Viktor.Haag@D2L.com> | 2019-06-18 16:22:25 +0300 |
commit | 6a054355d92628fbfa4670f097b5ce20db6fdc2e (patch) | |
tree | 19539ab1aaa8336120a6cf56d3e302dfb407a0e4 /sphinx/directives | |
parent | d19dd1c8dec8cc80229e8314cdbc37650b366eaf (diff) |
Simplify to ensure we're lazily setting the instance field-type-map variable
- We can more simply have ObjectDescription.get_field_type_map() make sure that
it's going to lazily set the value of an instance variable, not the class
variable, when it populates the field type map.
Diffstat (limited to 'sphinx/directives')
-rw-r--r-- | sphinx/directives/__init__.py | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/sphinx/directives/__init__.py b/sphinx/directives/__init__.py index 3eb3866f4..8a17fc0a5 100644 --- a/sphinx/directives/__init__.py +++ b/sphinx/directives/__init__.py @@ -70,25 +70,17 @@ 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 == {}: + 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): |