mirror of
https://github.com/davidhalter/jedi.git
synced 2026-04-25 03:43:59 +08:00
Fix a lot of test related typing issues
This commit is contained in:
@@ -3,6 +3,7 @@ import os
|
||||
from textwrap import dedent
|
||||
from itertools import count
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -301,7 +302,7 @@ def test_file_path_should_have_completions(Script):
|
||||
assert Script('r"').complete() # See GH #1503
|
||||
|
||||
|
||||
_dict_keys_completion_tests = [
|
||||
_dict_keys_completion_tests: "list[tuple[str, int | None, list[str | Any]]]" = [
|
||||
('ints[', 5, ['1', '50', Ellipsis]),
|
||||
('ints[]', 5, ['1', '50', Ellipsis]),
|
||||
('ints[1]', 5, ['1', '50', Ellipsis]),
|
||||
|
||||
@@ -32,7 +32,7 @@ def test_versions(version):
|
||||
try:
|
||||
env = get_system_environment(version)
|
||||
except InvalidPythonEnvironment:
|
||||
if int(version.replace('.', '')) == str(sys.version_info[0]) + str(sys.version_info[1]):
|
||||
if version.replace('.', '') == str(sys.version_info[0]) + str(sys.version_info[1]):
|
||||
# At least the current version has to work
|
||||
raise
|
||||
pytest.skip()
|
||||
|
||||
@@ -15,6 +15,7 @@ There are three kinds of test:
|
||||
|
||||
import textwrap
|
||||
from unittest import TestCase
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -22,6 +23,8 @@ import jedi
|
||||
|
||||
|
||||
class MixinTestFullName(object):
|
||||
assertEqual: Any
|
||||
|
||||
operation = None
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
||||
@@ -78,7 +78,7 @@ def test_numpy_like_non_zero():
|
||||
|
||||
def test_nested_resolve():
|
||||
class XX:
|
||||
def x():
|
||||
def x(): # type: ignore[misc]
|
||||
pass
|
||||
|
||||
cls = get_completion('XX', locals())
|
||||
@@ -92,7 +92,7 @@ def test_side_effect_completion():
|
||||
Python code, however we want references to Python code as well. Therefore
|
||||
we need some mixed kind of magic for tests.
|
||||
"""
|
||||
_GlobalNameSpace.SideEffectContainer.foo = 1
|
||||
_GlobalNameSpace.SideEffectContainer.foo = 1 # type: ignore[attr-defined]
|
||||
side_effect = get_completion('SideEffectContainer', _GlobalNameSpace.__dict__)
|
||||
|
||||
# It's a class that contains MixedObject.
|
||||
@@ -166,7 +166,7 @@ def test_getitem_side_effects():
|
||||
# Possible side effects here, should therefore not call this.
|
||||
if True:
|
||||
raise NotImplementedError()
|
||||
return index
|
||||
return index # type: ignore[unreachable]
|
||||
|
||||
foo = Foo2()
|
||||
_assert_interpreter_complete('foo["asdf"].upper', locals(), ['upper'])
|
||||
@@ -198,7 +198,7 @@ def test__getattr__completions(allow_unsafe_getattr, class_is_findable):
|
||||
raise AttributeError(name)
|
||||
|
||||
def __dir__(self):
|
||||
return ['foo', 'fbar'] + object.__dir__(self)
|
||||
return ['foo', 'fbar'] + object.__dir__(self) # type: ignore[operator]
|
||||
|
||||
if not class_is_findable:
|
||||
CompleteGetattr.__name__ = "something_somewhere"
|
||||
@@ -388,7 +388,7 @@ def test_dir_magic_method(allow_unsafe_getattr):
|
||||
raise AttributeError(name)
|
||||
|
||||
def __dir__(self):
|
||||
return ['foo', 'bar'] + object.__dir__(self)
|
||||
return ['foo', 'bar'] + object.__dir__(self) # type: ignore[operator]
|
||||
|
||||
itp = jedi.Interpreter("ca.", [{'ca': CompleteAttrs()}])
|
||||
completions = itp.complete()
|
||||
@@ -410,7 +410,7 @@ def test_dir_magic_method(allow_unsafe_getattr):
|
||||
def test_name_not_findable():
|
||||
class X():
|
||||
if 0:
|
||||
NOT_FINDABLE # noqa: F821
|
||||
NOT_FINDABLE # type: ignore[unreachable] # noqa: F821
|
||||
|
||||
def hidden(self):
|
||||
return
|
||||
@@ -493,7 +493,7 @@ def test__wrapped__():
|
||||
|
||||
def test_illegal_class_instance():
|
||||
class X:
|
||||
__class__ = 1
|
||||
__class__ = 1 # type: ignore[assignment]
|
||||
X.__name__ = 'asdf'
|
||||
d, = jedi.Interpreter('foo', [{'foo': X()}]).infer()
|
||||
v, = d._name.infer()
|
||||
@@ -537,7 +537,7 @@ def test_partial_signatures(code, expected, index):
|
||||
|
||||
def test_type_var():
|
||||
"""This was an issue before, see Github #1369"""
|
||||
x = typing.TypeVar('myvar')
|
||||
x = typing.TypeVar('myvar') # type: ignore[misc]
|
||||
def_, = jedi.Interpreter('x', [locals()]).infer()
|
||||
assert def_.name == 'TypeVar'
|
||||
|
||||
@@ -576,7 +576,7 @@ def test_dict_completion(code, column, expected):
|
||||
strs = {'asdf': 1, """foo""": 2, r'fbar': 3}
|
||||
mixed = {1: 2, 1.10: 4, None: 6, r'a\sdf': 8, b'foo': 9}
|
||||
|
||||
class Inherited(dict):
|
||||
class Inherited(dict): # type: ignore[type-arg]
|
||||
pass
|
||||
inherited = Inherited(blablu=3)
|
||||
|
||||
@@ -624,10 +624,10 @@ def test_dunders(class_is_findable, code, expected, allow_unsafe_getattr):
|
||||
def __getitem__(self, key) -> int:
|
||||
return 1
|
||||
|
||||
def __iter__(self, key) -> Iterator[str]:
|
||||
def __iter__(self, key) -> Iterator[str]: # type: ignore[empty-body]
|
||||
pass
|
||||
|
||||
def __next__(self, key) -> float:
|
||||
def __next__(self, key) -> float: # type: ignore[empty-body]
|
||||
pass
|
||||
|
||||
if not class_is_findable:
|
||||
|
||||
@@ -54,7 +54,7 @@ def test_rename_mod(Script, dir_with_content):
|
||||
''').format(dir=dir_with_content)
|
||||
|
||||
|
||||
@pytest.mark.skipif('sys.version_info[:2] < (3, 8)', message="Python 3.8 introduces dirs_exist_ok")
|
||||
@pytest.mark.skipif('sys.version_info[:2] < (3, 8)', reason="Python 3.8 introduces dirs_exist_ok")
|
||||
def test_namespace_package(Script, tmpdir):
|
||||
origin = get_example_dir('implicit_namespace_package')
|
||||
shutil.copytree(origin, tmpdir.strpath, dirs_exist_ok=True)
|
||||
|
||||
@@ -13,7 +13,7 @@ class SomeClass:
|
||||
def twice(self, b):
|
||||
pass
|
||||
|
||||
def some_function():
|
||||
def some_function(self):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user