def sub_modules_dict(self): """ Lists modules in the directory of this module (if this module is a package). """ names = {} if self.is_package(): mods = iter_module_names(self.inference_state, self.py__path__()) for name in mods: # It's obviously a relative import to the current module. names[name] = SubModuleName(self.as_context(), name) # In the case of an import like `from x.` we don't need to # add all the variables, this is only about submodules. return names
def _get_module_names(self, search_path=None, in_module=None): """ Get the names of all modules in the search_path. This means file names and not names defined in the files. """ names = [] # add builtin module names if search_path is None and in_module is None: names += [ImportName(self._module_context, name) for name in self._inference_state.compiled_subprocess.get_builtin_module_names()] if search_path is None: search_path = self._sys_path_with_modifications(is_completion=True) for name in iter_module_names(self._inference_state, search_path): if in_module is None: n = ImportName(self._module_context, name) else: n = SubModuleName(in_module.as_context(), name) names.append(n) return names