Removes symbols in a module that are not referenced by a docstring. Args: module_name: the name of the module (usually `__name__`). allowed_exception_list: a list of names that should not be removed. doc_string_modules: a list of modules from which to take the docstrings. If None,
(module_name, allowed_exception_list=None,
doc_string_modules=None)
| 84 | |
| 85 | |
| 86 | def remove_undocumented(module_name, allowed_exception_list=None, |
| 87 | doc_string_modules=None): |
| 88 | """Removes symbols in a module that are not referenced by a docstring. |
| 89 | |
| 90 | Args: |
| 91 | module_name: the name of the module (usually `__name__`). |
| 92 | allowed_exception_list: a list of names that should not be removed. |
| 93 | doc_string_modules: a list of modules from which to take the docstrings. |
| 94 | If None, then a list containing only the module named `module_name` is used. |
| 95 | |
| 96 | Furthermore, if a symbol previously added with `add_to_global_whitelist`, |
| 97 | then it will always be allowed. This is useful for internal tests. |
| 98 | |
| 99 | Returns: |
| 100 | None |
| 101 | """ |
| 102 | current_symbols = set(dir(_sys.modules[module_name])) |
| 103 | should_have = make_all(module_name, doc_string_modules) |
| 104 | should_have += allowed_exception_list or [] |
| 105 | extra_symbols = current_symbols - set(should_have) |
| 106 | target_module = _sys.modules[module_name] |
| 107 | for extra_symbol in extra_symbols: |
| 108 | # Skip over __file__, etc. Also preserves internal symbols. |
| 109 | if extra_symbol.startswith('_'): continue |
| 110 | fully_qualified_name = module_name + '.' + extra_symbol |
| 111 | _HIDDEN_ATTRIBUTES[fully_qualified_name] = (target_module, |
| 112 | getattr(target_module, |
| 113 | extra_symbol)) |
| 114 | delattr(target_module, extra_symbol) |
| 115 | |
| 116 | |
| 117 | __all__ = [ |
no test coverage detected