forked from VimPlug/jedi
Use "namespace" as a Name.type
This commit is contained in:
@@ -6,6 +6,8 @@ Changelog
|
|||||||
Unreleased
|
Unreleased
|
||||||
++++++++++
|
++++++++++
|
||||||
|
|
||||||
|
- Implict namespaces are now a separate types in ``Name().type``
|
||||||
|
|
||||||
0.18.0 (2020-12-25)
|
0.18.0 (2020-12-25)
|
||||||
+++++++++++++++++++
|
+++++++++++++++++++
|
||||||
|
|
||||||
|
|||||||
@@ -627,7 +627,7 @@ def search_in_module(inference_state, module_context, names, wanted_names,
|
|||||||
new_names = []
|
new_names = []
|
||||||
for n in names:
|
for n in names:
|
||||||
if s == n.string_name:
|
if s == n.string_name:
|
||||||
if n.tree_name is not None and n.api_type == 'module' \
|
if n.tree_name is not None and n.api_type in ('module', 'namespace') \
|
||||||
and ignore_imports:
|
and ignore_imports:
|
||||||
continue
|
continue
|
||||||
new_names += complete_trailer(
|
new_names += complete_trailer(
|
||||||
|
|||||||
@@ -439,5 +439,5 @@ def get_default_project(path=None):
|
|||||||
def _remove_imports(names):
|
def _remove_imports(names):
|
||||||
return [
|
return [
|
||||||
n for n in names
|
n for n in names
|
||||||
if n.tree_name is None or n.api_type != 'module'
|
if n.tree_name is None or n.api_type not in ('module', 'namespace')
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -156,8 +156,8 @@ def rename(inference_state, definitions, new_name):
|
|||||||
def inline(inference_state, names):
|
def inline(inference_state, names):
|
||||||
if not names:
|
if not names:
|
||||||
raise RefactoringError("There is no name under the cursor")
|
raise RefactoringError("There is no name under the cursor")
|
||||||
if any(n.api_type == 'module' for n in names):
|
if any(n.api_type in ('module', 'namespace') for n in names):
|
||||||
raise RefactoringError("Cannot inline imports or modules")
|
raise RefactoringError("Cannot inline imports, modules or namespaces")
|
||||||
if any(n.tree_name is None for n in names):
|
if any(n.tree_name is None for n in names):
|
||||||
raise RefactoringError("Cannot inline builtins/extensions")
|
raise RefactoringError("Cannot inline builtins/extensions")
|
||||||
|
|
||||||
|
|||||||
@@ -339,7 +339,7 @@ class Importer:
|
|||||||
values = self.follow()
|
values = self.follow()
|
||||||
for value in values:
|
for value in values:
|
||||||
# Non-modules are not completable.
|
# Non-modules are not completable.
|
||||||
if value.api_type != 'module': # not a module
|
if value.api_type not in ('module', 'namespace'): # not a module
|
||||||
continue
|
continue
|
||||||
if not value.is_compiled():
|
if not value.is_compiled():
|
||||||
# sub_modules_dict is not implemented for compiled modules.
|
# sub_modules_dict is not implemented for compiled modules.
|
||||||
|
|||||||
@@ -20,10 +20,7 @@ class ImplicitNamespaceValue(Value, SubModuleDictMixin):
|
|||||||
"""
|
"""
|
||||||
Provides support for implicit namespace packages
|
Provides support for implicit namespace packages
|
||||||
"""
|
"""
|
||||||
# Is a module like every other module, because if you import an empty
|
api_type = 'namespace'
|
||||||
# folder foobar it will be available as an object:
|
|
||||||
# <module 'foobar' (namespace)>.
|
|
||||||
api_type = 'module'
|
|
||||||
parent_context = None
|
parent_context = None
|
||||||
|
|
||||||
def __init__(self, inference_state, string_names, paths):
|
def __init__(self, inference_state, string_names, paths):
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ from import_tree import inline_mod
|
|||||||
#? 11 error
|
#? 11 error
|
||||||
test(inline_mod)
|
test(inline_mod)
|
||||||
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
Cannot inline imports or modules
|
Cannot inline imports, modules or namespaces
|
||||||
# -------------------------------------------------- module-works
|
# -------------------------------------------------- module-works
|
||||||
from import_tree import inline_mod
|
from import_tree import inline_mod
|
||||||
#? 22
|
#? 22
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ def test_implicit_nested_namespace_package(Script):
|
|||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
|
|
||||||
implicit_pkg, = Script(code, project=project).infer(column=10)
|
implicit_pkg, = Script(code, project=project).infer(column=10)
|
||||||
assert implicit_pkg.type == 'module'
|
assert implicit_pkg.type == 'namespace'
|
||||||
assert implicit_pkg.module_path is None
|
assert implicit_pkg.module_path is None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user