Fix a few more typing issues

This commit is contained in:
Dave Halter
2026-02-04 02:24:41 +01:00
parent 3ffed76884
commit e7fdbcc834
17 changed files with 38 additions and 23 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
import re import re
from textwrap import dedent from textwrap import dedent
from typing import Any
from inspect import Parameter from inspect import Parameter
from parso.python.token import PythonTokenTypes from parso.python.token import PythonTokenTypes
@@ -265,7 +266,7 @@ class Completion:
elif type_ == 'for_stmt': elif type_ == 'for_stmt':
allowed_transitions.append('else') allowed_transitions.append('else')
completion_names = [] completion_names: list[Any] = []
kwargs_only = False kwargs_only = False
if any(t in allowed_transitions for t in (PythonTokenTypes.NAME, if any(t in allowed_transitions for t in (PythonTokenTypes.NAME,
+1 -1
View File
@@ -254,7 +254,7 @@ def get_cached_default_environment():
# /path/to/env so we need to fully resolve the paths in order to # /path/to/env so we need to fully resolve the paths in order to
# compare them. # compare them.
if var and os.path.realpath(var) != os.path.realpath(environment.path): if var and os.path.realpath(var) != os.path.realpath(environment.path):
_get_cached_default_environment.clear_cache() _get_cached_default_environment.clear_cache() # type: ignore[attr-defined]
return _get_cached_default_environment() return _get_cached_default_environment()
return environment return environment
+1 -1
View File
@@ -93,7 +93,7 @@ def time_cache(seconds):
cache[key] = time.time(), result cache[key] = time.time(), result
return result return result
wrapper.clear_cache = lambda: cache.clear() wrapper.clear_cache = lambda: cache.clear() # type: ignore[attr-defined]
return wrapper return wrapper
return decorator return decorator
+1 -1
View File
@@ -36,7 +36,7 @@ try:
# pytest resets the stream at the end - causes troubles. Since # pytest resets the stream at the end - causes troubles. Since
# after every output the stream is reset automatically we don't # after every output the stream is reset automatically we don't
# need this. # need this.
initialise.atexit_done = True initialise.atexit_done = True # type: ignore[attr-defined]
try: try:
init(strip=False) init(strip=False)
except Exception: except Exception:
+1
View File
@@ -85,6 +85,7 @@ from jedi.plugins import plugin_manager
class InferenceState: class InferenceState:
analysis_modules: list[Any] analysis_modules: list[Any]
def __init__(self, project, environment=None, script_path=None): def __init__(self, project, environment=None, script_path=None):
if environment is None: if environment is None:
environment = project.get_environment() environment = project.get_environment()
+1 -1
View File
@@ -135,7 +135,7 @@ class _AbstractArgumentsMixin:
class AbstractArguments(_AbstractArgumentsMixin): class AbstractArguments(_AbstractArgumentsMixin):
context = None context = None
argument_node = None argument_node: Any = None
trailer = None trailer = None
+10 -5
View File
@@ -351,11 +351,16 @@ class _ValueWrapperBase(HelperValueMixin):
class LazyValueWrapper(_ValueWrapperBase): class LazyValueWrapper(_ValueWrapperBase):
@safe_property if TYPE_CHECKING:
@memoize_method @property
def _wrapped_value(self): def _wrapped_value(self) -> Any:
with debug.increase_indent_cm('Resolve lazy value wrapper'): return
return self._get_wrapped_value() else:
@safe_property
@memoize_method
def _wrapped_value(self):
with debug.increase_indent_cm('Resolve lazy value wrapper'):
return self._get_wrapped_value()
def __repr__(self): def __repr__(self):
return '<%s>' % (self.__class__.__name__) return '<%s>' % (self.__class__.__name__)
+2 -2
View File
@@ -39,7 +39,7 @@ def _is_type(obj):
def _shadowed_dict(klass): def _shadowed_dict(klass):
dict_attr = type.__dict__["__dict__"] dict_attr = type.__dict__["__dict__"] # type: ignore[index]
for entry in _static_getmro(klass): for entry in _static_getmro(klass):
try: try:
class_dict = dict_attr.__get__(entry)["__dict__"] class_dict = dict_attr.__get__(entry)["__dict__"]
@@ -54,7 +54,7 @@ def _shadowed_dict(klass):
def _static_getmro(klass): def _static_getmro(klass):
mro = type.__dict__['__mro__'].__get__(klass) mro = type.__dict__['__mro__'].__get__(klass) # type: ignore[index]
if not isinstance(mro, (tuple, list)): if not isinstance(mro, (tuple, list)):
# There are unfortunately no tests for this, I was not able to # There are unfortunately no tests for this, I was not able to
# reproduce this in pure Python. However should still solve the issue # reproduce this in pure Python. However should still solve the issue
@@ -158,7 +158,10 @@ def _find_module(string, path=None, full_name=None, is_global_search=True):
if loader is None and not spec.has_location: if loader is None and not spec.has_location:
# This is a namespace package. # This is a namespace package.
full_name = string if not path else full_name full_name = string if not path else full_name
implicit_ns_info = ImplicitNSInfo(full_name, spec.submodule_search_locations._path) implicit_ns_info = ImplicitNSInfo(
full_name,
spec.submodule_search_locations._path, # type: ignore[union-attr]
)
return implicit_ns_info, True return implicit_ns_info, True
break break
+2 -2
View File
@@ -109,7 +109,7 @@ def _search_function_arguments(module_context, funcdef, string_name):
if string_name == '__init__': if string_name == '__init__':
cls = get_parent_scope(funcdef) cls = get_parent_scope(funcdef)
if cls.type == 'classdef': if cls.type == 'classdef':
string_name = cls.name.value string_name = cls.name.value # type: ignore[union-attr]
compare_node = cls compare_node = cls
found_arguments = False found_arguments = False
@@ -203,7 +203,7 @@ def _check_name_for_execution(inference_state, context, compare_node, name, trai
# Here we're trying to find decorators by checking the first # Here we're trying to find decorators by checking the first
# parameter. It's not very generic though. Should find a better # parameter. It's not very generic though. Should find a better
# solution that also applies to nested decorators. # solution that also applies to nested decorators.
param_names = value.parent_context.get_param_names() param_names = value.parent_context.get_param_names() # type: ignore[attr-defined]
if len(param_names) != 1: if len(param_names) != 1:
continue continue
values = param_names[0].infer() values = param_names[0].infer()
+2 -2
View File
@@ -195,7 +195,7 @@ class GenericClass(DefineGenericBaseClass, ClassMixin):
@to_list @to_list
def py__bases__(self): def py__bases__(self):
for base in self._wrapped_value.py__bases__(): for base in self._wrapped_value.py__bases__(): # type: ignore[attr-defined]
yield _LazyGenericBaseClass(self, base, self._generics_manager) yield _LazyGenericBaseClass(self, base, self._generics_manager)
def _create_instance_with_generics(self, generics_manager): def _create_instance_with_generics(self, generics_manager):
@@ -384,7 +384,7 @@ class BaseTypingValue(LazyValueWrapper):
return _PseudoTreeNameClass(self.parent_context, self._tree_name) return _PseudoTreeNameClass(self.parent_context, self._tree_name)
def get_signatures(self): def get_signatures(self):
return self._wrapped_value.get_signatures() return self._wrapped_value.get_signatures() # type: ignore[attr-defined]
def __repr__(self): def __repr__(self):
return '%s(%s)' % (self.__class__.__name__, self._tree_name.value) return '%s(%s)' % (self.__class__.__name__, self._tree_name.value)
+3 -3
View File
@@ -245,7 +245,7 @@ class ValueNameMixin:
def get_root_context(self): def get_root_context(self):
if self.parent_context is None: # A module if self.parent_context is None: # A module
return self._value.as_context() return self._value.as_context()
return super().get_root_context() return super().get_root_context() # type: ignore
def get_defining_qualified_value(self): def get_defining_qualified_value(self):
context = self.parent_context context = self.parent_context
@@ -365,13 +365,13 @@ class _ParamMixin:
get_kind: Any get_kind: Any
def maybe_positional_argument(self, include_star=True): def maybe_positional_argument(self, include_star=True):
options = [Parameter.POSITIONAL_ONLY, Parameter.POSITIONAL_OR_KEYWORD] options: list[int] = [Parameter.POSITIONAL_ONLY, Parameter.POSITIONAL_OR_KEYWORD]
if include_star: if include_star:
options.append(Parameter.VAR_POSITIONAL) options.append(Parameter.VAR_POSITIONAL)
return self.get_kind() in options return self.get_kind() in options
def maybe_keyword_argument(self, include_stars=True): def maybe_keyword_argument(self, include_stars=True):
options = [Parameter.KEYWORD_ONLY, Parameter.POSITIONAL_OR_KEYWORD] options: list[int] = [Parameter.KEYWORD_ONLY, Parameter.POSITIONAL_OR_KEYWORD]
if include_stars: if include_stars:
options.append(Parameter.VAR_KEYWORD) options.append(Parameter.VAR_KEYWORD)
return self.get_kind() in options return self.get_kind() in options
+1 -1
View File
@@ -435,7 +435,7 @@ def _infer_expr_stmt(context, stmt, seek_name=None):
value_set = ValueSet(to_mod(v) for v in left_values) value_set = ValueSet(to_mod(v) for v in left_values)
else: else:
operator = copy.copy(first_operator) operator = copy.copy(first_operator)
operator.value = operator.value[:-1] # type: ignore[attor-defined] operator.value = operator.value[:-1]
for_stmt = stmt.search_ancestor('for_stmt') for_stmt = stmt.search_ancestor('for_stmt')
if for_stmt is not None and for_stmt.type == 'for_stmt' and value_set \ if for_stmt is not None and for_stmt.type == 'for_stmt' and value_set \
and parser_utils.for_stmt_defines_one_name(for_stmt): and parser_utils.for_stmt_defines_one_name(for_stmt):
+1
View File
@@ -189,6 +189,7 @@ class CompiledInstance(AbstractInstanceValue):
class _BaseTreeInstance(AbstractInstanceValue): class _BaseTreeInstance(AbstractInstanceValue):
get_defined_names: Any get_defined_names: Any
_arguments: Any
@property @property
def array_type(self): def array_type(self):
+1 -1
View File
@@ -233,7 +233,7 @@ class Sequence(LazyAttributeOverwrite, IterableMixin):
class _BaseComprehension(ComprehensionMixin): class _BaseComprehension(ComprehensionMixin):
def __init__(self, inference_state, defining_context, sync_comp_for_node, entry_node): def __init__(self, inference_state, defining_context, sync_comp_for_node, entry_node):
assert sync_comp_for_node.type == 'sync_comp_for' assert sync_comp_for_node.type == 'sync_comp_for'
super().__init__(inference_state) super().__init__(inference_state) # type: ignore[call-arg]
self._defining_context = defining_context self._defining_context = defining_context
self._sync_comp_for_node = sync_comp_for_node self._sync_comp_for_node = sync_comp_for_node
self._entry_node = entry_node self._entry_node = entry_node
+3
View File
@@ -694,6 +694,9 @@ class ClassValue(ClassMixin, FunctionAndClassBase, metaclass=CachedMetaClass):
""" """
bases_arguments = self._get_bases_arguments() bases_arguments = self._get_bases_arguments()
if bases_arguments is None:
return None
if bases_arguments.argument_node.type != "arglist": if bases_arguments.argument_node.type != "arglist":
# If it is not inheriting from the base model and having # If it is not inheriting from the base model and having
# extra parameters, then init behavior is not changed. # extra parameters, then init behavior is not changed.
+2 -1
View File
@@ -2,6 +2,7 @@
Module is used to infer Django model fields. Module is used to infer Django model fields.
""" """
from inspect import Parameter from inspect import Parameter
from typing import Any
from jedi import debug from jedi import debug
from jedi.inference.cache import inference_state_function_cache from jedi.inference.cache import inference_state_function_cache
@@ -140,7 +141,7 @@ def _new_dict_filter(cls, is_instance):
include_metaclasses=False, include_metaclasses=False,
include_type_when_class=False) include_type_when_class=False)
) )
dct = { dct: dict[str, Any] = {
name.string_name: DjangoModelName(cls, name, is_instance) name.string_name: DjangoModelName(cls, name, is_instance)
for filter_ in reversed(filters) for filter_ in reversed(filters)
for name in filter_.values() for name in filter_.values()