From: Vladimír Vondruš Date: Fri, 30 Aug 2019 16:33:05 +0000 (+0200) Subject: documentation/python: minor naming cleanup. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=e339969256b34c50ed3f8dc2d53f636649d7d873;p=blog.git documentation/python: minor naming cleanup. --- diff --git a/documentation/python.py b/documentation/python.py index 09de8234..4642f19f 100755 --- a/documentation/python.py +++ b/documentation/python.py @@ -175,7 +175,7 @@ default_config = { class State: def __init__(self, config): self.config = config - self.module_mapping: Dict[str, str] = {} + self.name_mapping: Dict[str, str] = {} self.module_docs: Dict[str, Dict[str, str]] = {} self.class_docs: Dict[str, Dict[str, str]] = {} self.enum_docs: Dict[str, Dict[str, str]] = {} @@ -198,7 +198,7 @@ class State: self.crawled: Set[object] = set() def map_name_prefix(state: State, type: str) -> str: - for prefix, replace in state.module_mapping.items(): + for prefix, replace in state.name_mapping.items(): if type == prefix or type.startswith(prefix + '.'): return replace + type[len(prefix):] @@ -483,13 +483,13 @@ def crawl_module(state: State, path: List[str], module) -> List[Tuple[List[str], # Modules have __name__ while other objects have __module__, need # to check both. if inspect.ismodule(object) and object.__name__ != '.'.join(subpath): - assert object.__name__ not in state.module_mapping - state.module_mapping[object.__name__] = '.'.join(subpath) + assert object.__name__ not in state.name_mapping + state.name_mapping[object.__name__] = '.'.join(subpath) elif hasattr(object, '__module__'): subname = object.__module__ + '.' + object.__name__ if subname != '.'.join(subpath): - assert subname not in state.module_mapping - state.module_mapping[subname] = '.'.join(subpath) + assert subname not in state.name_mapping + state.name_mapping[subname] = '.'.join(subpath) # Now extract the actual docs for name in module.__all__: diff --git a/documentation/test_python/test_pybind.py b/documentation/test_python/test_pybind.py index 1bb622e3..444e5b04 100644 --- a/documentation/test_python/test_pybind.py +++ b/documentation/test_python/test_pybind.py @@ -179,9 +179,9 @@ class Signature(unittest.TestCase): '(arg0: MyClass) -> float'), ('', '', [('arg0', 'MyClass', 'MyClass', None)], 'float', 'float')) - def test_module_mapping(self): - state = self.state - state.module_mapping['module._module'] = 'module' + def test_name_mapping(self): + state = copy.deepcopy(self.state) + state.name_mapping['module._module'] = 'module' self.assertEqual(parse_pybind_signature(state, [], 'foo(a: module._module.Foo, b: typing.Tuple[int, module._module.Bar]) -> module._module.Baz'),