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
+1
View File
@@ -85,6 +85,7 @@ from jedi.plugins import plugin_manager
class InferenceState:
analysis_modules: list[Any]
def __init__(self, project, environment=None, script_path=None):
if environment is None:
environment = project.get_environment()
+1 -1
View File
@@ -135,7 +135,7 @@ class _AbstractArgumentsMixin:
class AbstractArguments(_AbstractArgumentsMixin):
context = None
argument_node = None
argument_node: Any = None
trailer = None
+10 -5
View File
@@ -351,11 +351,16 @@ class _ValueWrapperBase(HelperValueMixin):
class LazyValueWrapper(_ValueWrapperBase):
@safe_property
@memoize_method
def _wrapped_value(self):
with debug.increase_indent_cm('Resolve lazy value wrapper'):
return self._get_wrapped_value()
if TYPE_CHECKING:
@property
def _wrapped_value(self) -> Any:
return
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):
return '<%s>' % (self.__class__.__name__)
+2 -2
View File
@@ -39,7 +39,7 @@ def _is_type(obj):
def _shadowed_dict(klass):
dict_attr = type.__dict__["__dict__"]
dict_attr = type.__dict__["__dict__"] # type: ignore[index]
for entry in _static_getmro(klass):
try:
class_dict = dict_attr.__get__(entry)["__dict__"]
@@ -54,7 +54,7 @@ def _shadowed_dict(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)):
# There are unfortunately no tests for this, I was not able to
# 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:
# This is a namespace package.
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
break
+2 -2
View File
@@ -109,7 +109,7 @@ def _search_function_arguments(module_context, funcdef, string_name):
if string_name == '__init__':
cls = get_parent_scope(funcdef)
if cls.type == 'classdef':
string_name = cls.name.value
string_name = cls.name.value # type: ignore[union-attr]
compare_node = cls
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
# parameter. It's not very generic though. Should find a better
# 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:
continue
values = param_names[0].infer()
+2 -2
View File
@@ -195,7 +195,7 @@ class GenericClass(DefineGenericBaseClass, ClassMixin):
@to_list
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)
def _create_instance_with_generics(self, generics_manager):
@@ -384,7 +384,7 @@ class BaseTypingValue(LazyValueWrapper):
return _PseudoTreeNameClass(self.parent_context, self._tree_name)
def get_signatures(self):
return self._wrapped_value.get_signatures()
return self._wrapped_value.get_signatures() # type: ignore[attr-defined]
def __repr__(self):
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):
if self.parent_context is None: # A module
return self._value.as_context()
return super().get_root_context()
return super().get_root_context() # type: ignore
def get_defining_qualified_value(self):
context = self.parent_context
@@ -365,13 +365,13 @@ class _ParamMixin:
get_kind: Any
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:
options.append(Parameter.VAR_POSITIONAL)
return self.get_kind() in options
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:
options.append(Parameter.VAR_KEYWORD)
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)
else:
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')
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):
+1
View File
@@ -189,6 +189,7 @@ class CompiledInstance(AbstractInstanceValue):
class _BaseTreeInstance(AbstractInstanceValue):
get_defined_names: Any
_arguments: Any
@property
def array_type(self):
+1 -1
View File
@@ -233,7 +233,7 @@ class Sequence(LazyAttributeOverwrite, IterableMixin):
class _BaseComprehension(ComprehensionMixin):
def __init__(self, inference_state, defining_context, sync_comp_for_node, entry_node):
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._sync_comp_for_node = sync_comp_for_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()
if bases_arguments is None:
return None
if bases_arguments.argument_node.type != "arglist":
# If it is not inheriting from the base model and having
# extra parameters, then init behavior is not changed.