chiark / gitweb /
documentation/python: minor naming cleanup.
authorVladimír Vondruš <mosra@centrum.cz>
Fri, 30 Aug 2019 16:33:05 +0000 (18:33 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Fri, 30 Aug 2019 18:37:46 +0000 (20:37 +0200)
documentation/python.py
documentation/test_python/test_pybind.py

index 09de823458c130ceb9e9ab7ff6cde08f7a1a4ba2..4642f19fb0ee6b4edc8e2187a2723dc898b7b17b 100755 (executable)
@@ -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__:
index 1bb622e3e21931f4ccf111d77b61dd15e2a00629..444e5b0494fbfe58af112cda9c51d70babeee97c 100644 (file)
@@ -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'),