Upgrade typeshed

This commit is contained in:
Dave Halter
2021-01-01 03:18:49 +01:00
parent 92d96ac336
commit d821451a64
11 changed files with 36 additions and 44 deletions

View File

@@ -54,7 +54,7 @@ a
#? int()
(3 ** 3)
#? int() str()
#? int()
(3 ** 'a')
#? int()
(3 + 'a')

View File

@@ -1,2 +0,0 @@
with open() as fin:
fin.read()

View File

@@ -173,7 +173,7 @@ def test_get_line_code(Script):
return Script(source).complete(line=line)[0].get_line_code(**kwargs).replace('\r', '')
# On builtin
assert get_line_code('abs') == 'def abs(__n: SupportsAbs[_T]) -> _T: ...\n'
assert get_line_code('abs') == 'def abs(__x: SupportsAbs[_T]) -> _T: ...\n'
# On custom code
first_line = 'def foo():\n'

View File

@@ -39,12 +39,11 @@ class TestSignatures(TestCase):
run = self._run_simple
# simple
s1 = "sorted(a, bool("
run(s1, 'sorted', 0, 7)
run(s1, 'sorted', 1, 9)
run(s1, 'sorted', 1, 10)
run(s1, 'sorted', None, 11)
run(s1, 'bool', 0, 15)
s1 = "tuple(a, bool("
run(s1, 'tuple', 0, 6)
run(s1, 'tuple', None, 8)
run(s1, 'tuple', None, 9)
run(s1, 'bool', 0, 14)
s2 = "abs(), "
run(s2, 'abs', 0, 4)
@@ -65,9 +64,9 @@ class TestSignatures(TestCase):
run(s4, 'abs', 0, 10)
run(s4, 'abs', None, 11)
s5 = "sorted(1,\nif 2:\n def a():"
run(s5, 'sorted', 0, 7)
run(s5, 'sorted', 1, 9)
s5 = "tuple(1,\nif 2:\n def a():"
run(s5, 'tuple', 0, 6)
run(s5, 'tuple', None, 8)
s6 = "bool().__eq__("
run(s6, '__eq__', 0)
@@ -89,8 +88,8 @@ class TestSignatures(TestCase):
def test_for(self):
# jedi-vim #11
self._run_simple("for sorted(", 'sorted', 0)
self._run_simple("for s in sorted(", 'sorted', 0)
self._run_simple("for tuple(", 'tuple', 0)
self._run_simple("for s in tuple(", 'tuple', 0)
def test_with(Script):
@@ -272,7 +271,7 @@ def test_pow_params(Script):
# See Github #1357.
for sig in Script('pow(').get_signatures():
param_names = [p.name for p in sig.params]
assert param_names in (['x', 'y'], ['x', 'y', 'z'])
assert param_names in (['base', 'exp'], ['base', 'exp', 'mod'])
def test_param_name(Script):

View File

@@ -195,7 +195,7 @@ def test_hashlib_params(Script, environment):
script = Script('from hashlib import sha256')
c, = script.complete()
sig, = c.get_signatures()
assert [p.name for p in sig.params] == ['arg']
assert [p.name for p in sig.params] == ['string']
def test_signature_params(Script):
@@ -619,7 +619,7 @@ def test_definition_goto_follow_imports(Script):
('n = next; n', 'Union[next(__i: Iterator[_T]) -> _T, '
'next(__i: Iterator[_T], default: _VT) -> Union[_T, _VT]]'),
('abs', 'abs(__n: SupportsAbs[_T]) -> _T'),
('abs', 'abs(__x: SupportsAbs[_T]) -> _T'),
('def foo(x, y): return x if xxxx else y\nfoo(str(), 1)\nfoo',
'foo(x: str, y: int) -> Union[int, str]'),
('def foo(x, y = None): return x if xxxx else y\nfoo(str(), 1)\nfoo',

View File

@@ -150,19 +150,6 @@ def test_async(Script, environment):
assert 'hey' in names
def test_method_doc_with_signature(Script):
code = 'f = open("")\nf.writelin'
c, = Script(code).complete()
assert c.name == 'writelines'
assert c.docstring() == 'writelines(lines: Iterable[AnyStr]) -> None'
def test_method_doc_with_signature2(Script):
code = 'f = open("")\nf.writelines'
d, = Script(code).goto()
assert d.docstring() == 'writelines(lines: Iterable[AnyStr]) -> None'
def test_with_stmt_error_recovery(Script):
assert Script('with open('') as foo: foo.\na').complete(line=1)

View File

@@ -95,7 +95,7 @@ def test_builtin_docstring(goto_or_help_or_infer):
d, = goto_or_help_or_infer('open')
doc = d.docstring()
assert doc.startswith('open(file: Union[')
assert doc.startswith('open(file: ')
assert 'Open file' in doc

View File

@@ -15,4 +15,4 @@ def test_module__file__(Script, environment):
def_, = Script('import antigravity; antigravity.__file__').infer()
value = def_._name._value.get_safe_value()
assert value.endswith('.py')
assert value.endswith('.pyi')

View File

@@ -21,10 +21,10 @@ def test_get_typeshed_directories():
def transform(set_):
return {x.replace('/', os.path.sep) for x in set_}
dirs = get_dirs(PythonVersionInfo(3, 6))
assert dirs == transform({'stdlib/2and3', 'stdlib/3',
'stdlib/3.6', 'third_party/2and3',
'third_party/3', 'third_party/3.6'})
dirs = get_dirs(PythonVersionInfo(3, 7))
assert dirs == transform({'stdlib/2and3', 'stdlib/3', 'stdlib/3.7',
'third_party/2and3',
'third_party/3', 'third_party/3.7'})
def test_get_stub_files():
@@ -92,7 +92,7 @@ def test_sys_exc_info(Script):
# It's an optional.
assert def_.name == 'BaseException'
assert def_.module_path == typeshed.TYPESHED_PATH.joinpath(
'stdlib', '2and3', 'builtins.pyi'
'stdlib', '3', 'builtins.pyi'
)
assert def_.type == 'instance'
assert none.name == 'NoneType'

View File

@@ -227,14 +227,22 @@ def test_nested_signatures(Script, environment, combination, expected):
assert expected == computed
def test_pow_signature(Script):
def test_pow_signature(Script, environment):
# See github #1357
sigs = Script('pow(').get_signatures()
strings = {sig.to_string() for sig in sigs}
assert strings == {'pow(x: float, y: float, z: float, /) -> float',
'pow(x: float, y: float, /) -> float',
'pow(x: int, y: int, z: int, /) -> Any',
'pow(x: int, y: int, /) -> Any'}
if environment.version_info < (3, 8):
assert strings == {'pow(base: _SupportsPow2[_E, _T_co], exp: _E, /) -> _T_co',
'pow(base: _SupportsPow3[_E, _M, _T_co], exp: _E, mod: _M, /) -> _T_co',
'pow(base: float, exp: float, mod: None=..., /) -> float',
'pow(base: int, exp: int, mod: None=..., /) -> Any',
'pow(base: int, exp: int, mod: int, /) -> int'}
else:
assert strings == {'pow(base: _SupportsPow2[_E, _T_co], exp: _E) -> _T_co',
'pow(base: _SupportsPow3[_E, _M, _T_co], exp: _E, mod: _M) -> _T_co',
'pow(base: float, exp: float, mod: None=...) -> float',
'pow(base: int, exp: int, mod: None=...) -> Any',
'pow(base: int, exp: int, mod: int) -> int'}
@pytest.mark.parametrize(