1
0
forked from VimPlug/jedi

Change a few tests to match new typeshed

This commit is contained in:
Dave Halter
2026-04-29 09:30:49 +02:00
parent 04e5f5b3b8
commit fe0369436e
11 changed files with 29 additions and 25 deletions
+2 -2
View File
@@ -233,12 +233,12 @@ def a():
# str literals in comment """ upper # str literals in comment """ upper
def completion_in_comment(): def completion_in_comment():
#? ['Exception'] #? ['Exception', 'ExceptionGroup']
# might fail because the comment is not a leaf: Exception # might fail because the comment is not a leaf: Exception
pass pass
some_word some_word
#? ['Exception'] #? ['Exception', 'ExceptionGroup']
# Very simple comment completion: Exception # Very simple comment completion: Exception
# Commment after it # Commment after it
+6 -6
View File
@@ -114,27 +114,27 @@ x(1, bar=2, ba)
x(1, ba, baz=3) x(1, ba, baz=3)
#? 14 ['baz='] #? 14 ['baz=']
x(1, bar=2, baz=3) x(1, bar=2, baz=3)
#? 7 ['BaseException'] #? 7 ['BaseException', 'BaseExceptionGroup']
x(basee) x(basee)
#? 22 ['bar=', 'baz='] #? 22 ['bar=', 'baz=']
x(1, 2, 3, 4, 5, 6, bar=2) x(1, 2, 3, 4, 5, 6, bar=2)
#? 14 ['baz='] #? 14 ['baz=']
y(1, bar=2, ba) y(1, bar=2, ba)
#? 7 ['bar=', 'BaseException', 'baz='] #? 7 ['bar=', 'BaseException', 'BaseExceptionGroup', 'baz=']
y(1, ba, baz=3) y(1, ba, baz=3)
#? 14 ['baz='] #? 14 ['baz=']
y(1, bar=2, baz=3) y(1, bar=2, baz=3)
#? 7 ['BaseException'] #? 7 ['BaseException', 'BaseExceptionGroup']
y(basee) y(basee)
#? 22 ['bar=', 'BaseException', 'baz='] #? 22 ['bar=', 'BaseException', 'BaseExceptionGroup', 'baz=']
y(1, 2, 3, 4, 5, 6, bar=2) y(1, 2, 3, 4, 5, 6, bar=2)
#? 11 ['bar=', 'bas='] #? 11 ['bar=', 'bas=']
z(bam=1, bar=2, bas=3) z(bam=1, bar=2, bas=3)
#? 8 ['BaseException', 'bas='] #? 8 ['BaseException', 'BaseExceptionGroup', 'bas=']
z(1, bas=2) z(1, bas=2)
#? 12 ['BaseException'] #? 12 ['BaseException', 'BaseExceptionGroup']
z(1, bas=bas) z(1, bas=bas)
#? 19 ['dict'] #? 19 ['dict']
+1 -1
View File
@@ -34,7 +34,7 @@ def we_can_has_sequence(p: Sequence[int], q: Sequence[B], r: Sequence[int],
t[1] t[1]
#? ["append"] #? ["append"]
u.a u.a
#? float() list() #? float()
u[1.0] u[1.0]
#? float() #? float()
u[1] u[1]
+1 -1
View File
@@ -360,7 +360,7 @@ X.attr_x.value
X.attr_y.name X.attr_y.name
#? float() #? float()
X.attr_y.value X.attr_y.value
#? str() #?
X().name X().name
#? float() #? float()
X().attr_x.attr_y.value X().attr_x.attr_y.value
+3 -3
View File
@@ -192,7 +192,7 @@ def test_hashlib_params(Script):
script = Script('from hashlib import sha256') script = Script('from hashlib import sha256')
c, = script.complete() c, = script.complete()
sig, = c.get_signatures() sig, = c.get_signatures()
assert [p.name for p in sig.params] == ['string'] assert [p.name for p in sig.params] == ['data', 'usedforsecurity', 'string']
def test_signature_params(Script): def test_signature_params(Script):
@@ -465,7 +465,7 @@ def test_import(get_names):
nms = nms[2].goto() nms = nms[2].goto()
assert nms assert nms
assert all(n.type == 'module' for n in nms) assert all(n.type == 'module' for n in nms)
assert 'posixpath' in {n.name for n in nms} assert 'path' in {n.name for n in nms}
nms = get_names('import os.path', references=True) nms = get_names('import os.path', references=True)
n = nms[0].goto()[0] n = nms[0].goto()[0]
@@ -616,7 +616,7 @@ def test_definition_goto_follow_imports(Script):
('n = next; n', 'Union[next(__i: Iterator[_T]) -> _T, ' ('n = next; n', 'Union[next(__i: Iterator[_T]) -> _T, '
'next(__i: Iterator[_T], default: _VT) -> Union[_T, _VT]]'), 'next(__i: Iterator[_T], default: _VT) -> Union[_T, _VT]]'),
('abs', 'abs(__x: SupportsAbs[_T]) -> _T'), ('abs', 'abs(x: SupportsAbs[_T], /) -> _T'),
('def foo(x, y): return x if xxxx else y\nfoo(str(), 1)\nfoo', ('def foo(x, y): return x if xxxx else y\nfoo(str(), 1)\nfoo',
'foo(x: str, y: int) -> Union[int, str]'), 'foo(x: str, y: int) -> Union[int, str]'),
('def foo(x, y = None): return x if xxxx else y\nfoo(str(), 1)\nfoo', ('def foo(x, y = None): return x if xxxx else y\nfoo(str(), 1)\nfoo',
+1 -1
View File
@@ -52,7 +52,7 @@ class TestFullNameWithGotoDefinitions(MixinTestFullName, TestCase):
self.check(""" self.check("""
import re import re
any_re = re.compile('.*') any_re = re.compile('.*')
any_re""", 'typing.Pattern') any_re""", 're.Pattern')
def test_from_import(self): def test_from_import(self):
self.check('from os import path', 'os.path') self.check('from os import path', 'os.path')
+1 -1
View File
@@ -68,4 +68,4 @@ def test_param_kind_and_name(code, index, param_code, kind, Script):
def test_staticmethod(Script): def test_staticmethod(Script):
s, = Script('staticmethod(').get_signatures() s, = Script('staticmethod(').get_signatures()
assert s.to_string() == 'staticmethod(f: Callable[..., Any])' assert s.to_string() == 'staticmethod(f: Callable[_P, _R_co], /)'
+1 -1
View File
@@ -86,7 +86,7 @@ def test_time_docstring():
import time import time
comp, = jedi.Script('import time\ntime.sleep').complete() comp, = jedi.Script('import time\ntime.sleep').complete()
assert comp.docstring(raw=True) == time.sleep.__doc__ assert comp.docstring(raw=True) == time.sleep.__doc__
expected = 'sleep(secs: float) -> None\n\n' + time.sleep.__doc__ expected = 'sleep(seconds: _SupportsFloatOrIndex, /) -> None\n\n' + time.sleep.__doc__
assert comp.docstring() == expected assert comp.docstring() == expected
+1 -1
View File
@@ -60,7 +60,7 @@ def test_instance_doc(Script):
'''Docstring of `TestClass`.''' '''Docstring of `TestClass`.'''
tc = TestClass() tc = TestClass()
tc""").infer() tc""").infer()
assert defs[0].docstring() == 'Docstring of `TestClass`.' assert defs[0].docstring() == 'TestClass()\n\nDocstring of `TestClass`.'
def test_multiple_docstrings(Script): def test_multiple_docstrings(Script):
@@ -10,20 +10,20 @@ def test_sqlite3_conversion(Script):
script1 = Script('import sqlite3; sqlite3.Connection') script1 = Script('import sqlite3; sqlite3.Connection')
d, = script1.infer() d, = script1.infer()
assert not d.module_path assert d.module_path
assert d.full_name == 'sqlite3.Connection' assert d.full_name == 'sqlite3.Connection'
assert convert_names([d._name], only_stubs=True) assert convert_names([d._name], only_stubs=True)
d, = script1.infer(only_stubs=True) d, = script1.infer(only_stubs=True)
assert d.is_stub() assert d.is_stub()
assert d.full_name == 'sqlite3.dbapi2.Connection' assert d.full_name == 'sqlite3.Connection'
script2 = Script(path=d.module_path) script2 = Script(path=d.module_path)
d, = script2.infer(line=d.line, column=d.column) d, = script2.infer(line=d.line, column=d.column)
assert not d.is_stub() assert d.is_stub()
assert d.full_name == 'sqlite3.Connection' assert d.full_name == 'sqlite3.Connection'
v, = d._name.infer() v, = d._name.infer()
assert v.is_compiled() assert not v.is_compiled()
def test_conversion_of_stub_only(Script): def test_conversion_of_stub_only(Script):
@@ -70,11 +70,11 @@ def test_stub_get_line_code(Script):
script = Script(code) script = Script(code)
d, = script.goto(only_stubs=True) d, = script.goto(only_stubs=True)
# Replace \r for tests on Windows # Replace \r for tests on Windows
assert d.get_line_code().replace('\r', '') == 'class ABC(metaclass=ABCMeta): ...\n' assert d.get_line_code().replace('\r', '') == 'class ABC(metaclass=ABCMeta):\n'
del parser_cache[script._inference_state.latest_grammar._hashed][d.module_path] del parser_cache[script._inference_state.latest_grammar._hashed][d.module_path]
d, = Script(path=d.module_path).goto(d.line, d.column, only_stubs=True) d, = Script(path=d.module_path).goto(d.line, d.column, only_stubs=True)
assert d.is_stub() assert d.is_stub()
assert d.get_line_code().replace('\r', '') == 'class ABC(metaclass=ABCMeta): ...\n' assert d.get_line_code().replace('\r', '') == 'class ABC(metaclass=ABCMeta):\n'
def test_os_stat_result(Script): def test_os_stat_result(Script):
+6 -2
View File
@@ -36,7 +36,7 @@ class TestSetupReadline(unittest.TestCase):
assert self.complete('list') == ['list'] assert self.complete('list') == ['list']
assert self.complete('importerror') == ['ImportError'] assert self.complete('importerror') == ['ImportError']
s = "print(BaseE" s = "print(BaseE"
assert self.complete(s) == [s + 'xception'] assert self.complete(s) == [s + 'xception', s + 'xceptionGroup']
def test_nested(self): def test_nested(self):
assert self.complete('list.Insert') == ['list.insert'] assert self.complete('list.Insert') == ['list.insert']
@@ -69,7 +69,11 @@ class TestSetupReadline(unittest.TestCase):
def test_import(self): def test_import(self):
s = 'from os.path import a' s = 'from os.path import a'
assert set(self.complete(s)) == {s + 'ltsep', s + 'bspath'} assert set(self.complete(s)) == {
s + 'ltsep',
s + 'bspath',
'from os.path import ALLOW_MISSING'
}
assert self.complete('import keyword') == ['import keyword'] assert self.complete('import keyword') == ['import keyword']
import os import os