Show More
@@ -154,6 +154,17 b' def is_importable(module, attr, only_modules):' | |||||
154 | else: |
|
154 | else: | |
155 | return not(attr[:2] == '__' and attr[-2:] == '__') |
|
155 | return not(attr[:2] == '__' and attr[-2:] == '__') | |
156 |
|
156 | |||
|
157 | def is_possible_submodule(module, attr): | |||
|
158 | try: | |||
|
159 | obj = getattr(module, attr) | |||
|
160 | except AttributeError: | |||
|
161 | # Is possilby an unimported submodule | |||
|
162 | return True | |||
|
163 | except TypeError: | |||
|
164 | # https://github.com/ipython/ipython/issues/9678 | |||
|
165 | return False | |||
|
166 | return inspect.ismodule(obj) | |||
|
167 | ||||
157 |
|
168 | |||
158 | def try_import(mod: str, only_modules=False) -> List[str]: |
|
169 | def try_import(mod: str, only_modules=False) -> List[str]: | |
159 | """ |
|
170 | """ | |
@@ -172,7 +183,12 b' def try_import(mod: str, only_modules=False) -> List[str]:' | |||||
172 | completions.extend( [attr for attr in dir(m) if |
|
183 | completions.extend( [attr for attr in dir(m) if | |
173 | is_importable(m, attr, only_modules)]) |
|
184 | is_importable(m, attr, only_modules)]) | |
174 |
|
185 | |||
175 |
|
|
186 | m_all = getattr(m, "__all__", []) | |
|
187 | if only_modules: | |||
|
188 | completions.extend(attr for attr in m_all if is_possible_submodule(m, attr)) | |||
|
189 | else: | |||
|
190 | completions.extend(m_all) | |||
|
191 | ||||
176 | if m_is_init: |
|
192 | if m_is_init: | |
177 | completions.extend(module_list(os.path.dirname(m.__file__))) |
|
193 | completions.extend(module_list(os.path.dirname(m.__file__))) | |
178 | completions_set = {c for c in completions if isinstance(c, str)} |
|
194 | completions_set = {c for c in completions if isinstance(c, str)} |
General Comments 0
You need to be logged in to leave comments.
Login now