os.path.sep should always have a clear value

This commit is contained in:
Dave Halter
2019-08-06 19:57:16 +02:00
parent 99008eef43
commit 81488bcd20
4 changed files with 17 additions and 5 deletions

View File

@@ -7,7 +7,7 @@ Changelog
+++++++++++++++++++
- Added file path completions, there's a **new ``Completion.type``** ``path``,
now.
now. Example: ``'/ho`` -> ``'/home/``
- ``*args``/``**kwargs`` resolving. If possible Jedi replaces the parameters
with the actual alternatives.
- Better support for enums/dataclasses

View File

@@ -27,6 +27,7 @@ from jedi.evaluate.cache import evaluator_method_cache
from jedi.evaluate.gradual.stub_context import VersionInfo
from jedi.evaluate.gradual import annotation
from jedi.evaluate.context.decorator import Decoratee
from jedi.plugins import plugin_manager
def _limit_context_infers(func):
@@ -545,6 +546,7 @@ def _remove_statements(evaluator, context, stmt, name):
return eval_expr_stmt(context, stmt, seek_name=name)
@plugin_manager.decorate()
def tree_name_to_contexts(evaluator, context, tree_name):
context_set = NO_CONTEXTS
module_node = context.get_root_context().tree_node

View File

@@ -789,3 +789,13 @@ class EnumInstance(LazyContextWrapper):
))
for f in self._get_wrapped_context().get_filters():
yield f
def tree_name_to_contexts(func):
def wrapper(evaluator, context, tree_name):
if tree_name.value == 'sep' and context.is_module() and context.py__name__() == 'os.path':
return ContextSet({
compiled.create_simple_object(evaluator, os.path.sep),
})
return func(evaluator, context, tree_name)
return wrapper

View File

@@ -161,6 +161,7 @@ def test_keyword_completion(Script, code, has_keywords):
f1 = join(root_dir, 'example.py')
f2 = join(root_dir, 'test', 'example.py')
os_path = 'from os.path import *\n'
@pytest.mark.parametrize(
@@ -205,10 +206,9 @@ f2 = join(root_dir, 'test', 'example.py')
('example.py', '"test" + "', None, [s]),
# __file__
(f1, 'from os.path import *\ndirname(__file__) + "%stest' % s, None, [s]),
(f2, 'from os.path import *\ndirname(__file__) + "%stest_ca' % s, None, ['che.py']),
(f2, 'from os.path import *\ndirname(abspath(__file__)) + "%stest_ca' % s,
None, ['che.py']),
(f1, os_path + 'dirname(__file__) + "%stest' % s, None, [s]),
(f2, os_path + 'dirname(__file__) + "%stest_ca' % s, None, ['che.py']),
(f2, os_path + 'dirname(abspath(__file__)) + sep + "test_ca', None, ['che.py']),
]
)
def test_file_path_completions(Script, file, code, column, expected):