forked from VimPlug/jedi
Merge branch 'master' into refactor
This commit is contained in:
@@ -422,3 +422,11 @@ with Foo() as f3:
|
||||
#? 6 Foo
|
||||
with Foo() as f3:
|
||||
f3
|
||||
|
||||
# -----------------
|
||||
# Avoiding multiple definitions
|
||||
# -----------------
|
||||
|
||||
some_array = ['', '']
|
||||
#! ['def upper']
|
||||
some_array[some_not_defined_index].upper
|
||||
|
||||
@@ -499,3 +499,89 @@ def dynamic_annotation(x: int):
|
||||
|
||||
#? int()
|
||||
dynamic_annotation('')
|
||||
|
||||
# -------------------------
|
||||
# TypeDict
|
||||
# -------------------------
|
||||
|
||||
# python >= 3.8
|
||||
|
||||
class Foo(typing.TypedDict):
|
||||
foo: str
|
||||
bar: typing.List[float]
|
||||
an_int: int
|
||||
#! ['foo: str']
|
||||
foo
|
||||
#? str()
|
||||
foo
|
||||
#? int()
|
||||
an_int
|
||||
|
||||
def typed_dict_test_foo(arg: Foo):
|
||||
a_string = arg['foo']
|
||||
a_list_of_floats = arg['bar']
|
||||
an_int = arg['an_int']
|
||||
|
||||
#? str()
|
||||
a_string
|
||||
#? list()
|
||||
a_list_of_floats
|
||||
#? float()
|
||||
a_list_of_floats[0]
|
||||
#? int()
|
||||
an_int
|
||||
|
||||
#? ['isupper']
|
||||
a_string.isuppe
|
||||
#? ['pop']
|
||||
a_list_of_floats.po
|
||||
#? ['as_integer_ratio']
|
||||
an_int.as_integer_rati
|
||||
|
||||
#! ['class Foo']
|
||||
d: Foo
|
||||
#? str()
|
||||
d['foo']
|
||||
#? float()
|
||||
d['bar'][0]
|
||||
#?
|
||||
d['baz']
|
||||
|
||||
#?
|
||||
d.foo
|
||||
#?
|
||||
d.bar
|
||||
#! []
|
||||
d.foo
|
||||
|
||||
#? []
|
||||
Foo.set
|
||||
#? ['setdefault']
|
||||
d.setdefaul
|
||||
#? []
|
||||
Foo.setdefaul
|
||||
|
||||
#? 5 ["'foo"]
|
||||
d['fo']
|
||||
#? 5 ['"bar"']
|
||||
d["bar"]
|
||||
|
||||
class Bar(Foo):
|
||||
another_variable: int
|
||||
|
||||
#? int()
|
||||
another_variable
|
||||
#?
|
||||
an_int
|
||||
|
||||
def typed_dict_test_foo(arg: Bar):
|
||||
#? str()
|
||||
arg['foo']
|
||||
#? list()
|
||||
arg['bar']
|
||||
#? float()
|
||||
arg['bar'][0]
|
||||
#? int()
|
||||
arg['an_int']
|
||||
#? int()
|
||||
arg['another_variable']
|
||||
|
||||
@@ -57,7 +57,7 @@ Foo.baz
|
||||
Foo().baz
|
||||
|
||||
class VarClass:
|
||||
var_instance1: int = 1
|
||||
var_instance1: int = ''
|
||||
var_instance2: float
|
||||
var_class1: typing.ClassVar[str] = 1
|
||||
var_class2: typing.ClassVar[bytes]
|
||||
@@ -77,9 +77,9 @@ class VarClass:
|
||||
self.var_
|
||||
|
||||
|
||||
#? ['var_class1', 'var_class2']
|
||||
#? ['var_class1', 'var_class2', 'var_instance1']
|
||||
VarClass.var_
|
||||
#?
|
||||
#? int()
|
||||
VarClass.var_instance1
|
||||
#?
|
||||
VarClass.var_instance2
|
||||
|
||||
@@ -91,3 +91,15 @@ class B:
|
||||
for i in self.a(i):
|
||||
#?
|
||||
yield i
|
||||
|
||||
|
||||
foo = int
|
||||
foo = foo # type: foo
|
||||
#? int
|
||||
foo
|
||||
|
||||
while True:
|
||||
bar = int
|
||||
bar = bar # type: bar
|
||||
#? int()
|
||||
bar
|
||||
|
||||
@@ -8,7 +8,7 @@ import pytest
|
||||
from . import helpers
|
||||
from . import run
|
||||
from . import refactor
|
||||
from jedi.api.environment import InterpreterEnvironment, get_system_environment
|
||||
from jedi import InterpreterEnvironment, get_system_environment
|
||||
from jedi.inference.compiled.value import create_from_access_path
|
||||
from jedi.inference.imports import _load_python_module
|
||||
from jedi.file_io import KnownContentFileIO
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from os.path import join, sep as s, dirname
|
||||
from os.path import join, sep as s, dirname, expanduser
|
||||
import os
|
||||
import sys
|
||||
from textwrap import dedent
|
||||
@@ -7,6 +7,7 @@ import pytest
|
||||
|
||||
from ..helpers import root_dir
|
||||
from jedi.api.helpers import _start_match, _fuzzy_match
|
||||
from jedi._compatibility import scandir
|
||||
|
||||
|
||||
def test_in_whitespace(Script):
|
||||
@@ -86,6 +87,18 @@ def test_loading_unicode_files_with_bad_global_charset(Script, monkeypatch, tmpd
|
||||
s.complete(line=2, column=4)
|
||||
|
||||
|
||||
def test_complete_expanduser(Script):
|
||||
possibilities = scandir(expanduser('~'))
|
||||
non_dots = [p for p in possibilities if not p.name.startswith('.') and len(p.name) > 1]
|
||||
item = non_dots[0]
|
||||
line = "'~%s%s'" % (os.sep, item.name)
|
||||
s = Script(line, line=1, column=len(line)-1)
|
||||
expected_name = item.name
|
||||
if item.is_dir():
|
||||
expected_name += os.path.sep
|
||||
assert expected_name in [c.name for c in s.completions()]
|
||||
|
||||
|
||||
def test_fake_subnodes(Script):
|
||||
"""
|
||||
Test the number of subnodes of a fake object.
|
||||
|
||||
@@ -342,7 +342,7 @@ def test_completion_params():
|
||||
|
||||
@pytest.mark.skipif('py_version < 33', reason='inspect.signature was created in 3.3.')
|
||||
def test_completion_param_annotations():
|
||||
# Need to define this function not directly in Python. Otherwise Jedi is to
|
||||
# Need to define this function not directly in Python. Otherwise Jedi is too
|
||||
# clever and uses the Python code instead of the signature object.
|
||||
code = 'def foo(a: 1, b: str, c: int = 1.0) -> bytes: pass'
|
||||
exec_(code, locals())
|
||||
@@ -354,6 +354,10 @@ def test_completion_param_annotations():
|
||||
assert [d.name for d in b.infer()] == ['str']
|
||||
assert {d.name for d in c.infer()} == {'int', 'float'}
|
||||
|
||||
assert a.description == 'param a: 1'
|
||||
assert b.description == 'param b: str'
|
||||
assert c.description == 'param c: int=1.0'
|
||||
|
||||
d, = jedi.Interpreter('foo()', [locals()]).infer()
|
||||
assert d.name == 'bytes'
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ def test_namedtuple_infer(Script):
|
||||
|
||||
assert d1.get_line_code() == "class Foo(tuple):\n"
|
||||
assert d1.module_path is None
|
||||
assert d1.docstring() == 'Foo(id, timestamp, gps_timestamp, attributes)'
|
||||
|
||||
|
||||
def test_re_sub(Script, environment):
|
||||
|
||||
@@ -41,6 +41,9 @@ def test_completion(case, monkeypatch, environment, has_typing):
|
||||
if skip_reason is not None:
|
||||
pytest.skip(skip_reason)
|
||||
|
||||
if 'pep0484_typing' in case.path and sys.version_info[0] == 2:
|
||||
pytest.skip('ditch python 2 finally')
|
||||
|
||||
_CONTAINS_TYPING = ('pep0484_typing', 'pep0484_comments', 'pep0526_variables')
|
||||
if not has_typing and any(x in case.path for x in _CONTAINS_TYPING):
|
||||
pytest.skip('Needs the typing module installed to run this test.')
|
||||
|
||||
Reference in New Issue
Block a user