diff options
Diffstat (limited to 'pylint/checkers/typecheck.py')
-rw-r--r-- | pylint/checkers/typecheck.py | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 1a628f231..97a7460a8 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -1,6 +1,6 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Try to find more bugs in the code using astroid inference capabilities.""" @@ -14,9 +14,9 @@ import shlex import sys import types from collections.abc import Callable, Iterable, Iterator, Sequence -from functools import singledispatch +from functools import cached_property, singledispatch from re import Pattern -from typing import TYPE_CHECKING, Any, TypeVar, Union +from typing import TYPE_CHECKING, Any, Literal, TypeVar, Union import astroid import astroid.exceptions @@ -53,13 +53,6 @@ from pylint.constants import PY310_PLUS from pylint.interfaces import HIGH, INFERENCE from pylint.typing import MessageDefinitionTuple -if sys.version_info >= (3, 8): - from functools import cached_property - from typing import Literal -else: - from astroid.decorators import cachedproperty as cached_property - from typing_extensions import Literal - if TYPE_CHECKING: from pylint.lint import PyLinter @@ -125,7 +118,7 @@ def _is_owner_ignored( matches any name from the *ignored_classes* or if its qualified name can be found in *ignored_classes*. """ - if is_module_ignored(owner.root(), ignored_modules): + if is_module_ignored(owner.root().qname(), ignored_modules): return True # Match against ignored classes. @@ -158,7 +151,7 @@ def _(node: nodes.ClassDef | bases.Instance) -> Iterable[str]: def _string_distance(seq1: str, seq2: str) -> int: seq2_length = len(seq2) - row = list(range(1, seq2_length + 1)) + [0] + row = [*list(range(1, seq2_length + 1)), 0] for seq1_index, seq1_char in enumerate(seq1): last_row = row row = [0] * seq2_length + [seq1_index + 1] @@ -733,7 +726,9 @@ def _no_context_variadic( else: inferred_statement = inferred.statement(future=True) - if not length and isinstance(inferred_statement, nodes.Lambda): + if not length and isinstance( + inferred_statement, (nodes.Lambda, nodes.FunctionDef) + ): is_in_starred_context = _has_parent_of_type(node, variadic_type, statement) used_as_starred_argument = any( variadic.value == name or variadic.value.parent_of(name) @@ -1569,6 +1564,11 @@ accessed. Python regular expressions are accepted.", node=node, args=(keyword, callable_name), ) + elif ( + keyword in [arg.name for arg in called.args.posonlyargs] + and called.args.kwarg + ): + pass else: parameters[i] = (parameters[i][0], True) elif keyword in kwparams: @@ -1654,7 +1654,7 @@ accessed. Python regular expressions are accepted.", if not isinstance(inferred, nodes.FunctionDef): return False - for return_value in inferred.infer_call_result(): + for return_value in inferred.infer_call_result(caller=None): # infer_call_result() returns nodes.Const.None for None return values # so this also catches non-returning decorators if not isinstance(return_value, nodes.FunctionDef): @@ -1685,9 +1685,9 @@ accessed. Python regular expressions are accepted.", # Determine what method on the parent this index will use # The parent of this node will be a Subscript, and the parent of that # node determines if the Subscript is a get, set, or delete operation. - if subscript.ctx is astroid.Store: + if subscript.ctx is astroid.Context.Store: methodname = "__setitem__" - elif subscript.ctx is astroid.Del: + elif subscript.ctx is astroid.Context.Del: methodname = "__delitem__" else: methodname = "__getitem__" @@ -2015,7 +2015,7 @@ accessed. Python regular expressions are accepted.", # TODO: This check was disabled (by adding the leading underscore) # due to false positives several years ago - can we re-enable it? - # https://github.com/PyCQA/pylint/issues/6359 + # https://github.com/pylint-dev/pylint/issues/6359 @only_required_for_messages("unsupported-binary-operation") def _visit_binop(self, node: nodes.BinOp) -> None: """Detect TypeErrors for binary arithmetic operands.""" @@ -2023,7 +2023,7 @@ accessed. Python regular expressions are accepted.", # TODO: This check was disabled (by adding the leading underscore) # due to false positives several years ago - can we re-enable it? - # https://github.com/PyCQA/pylint/issues/6359 + # https://github.com/pylint-dev/pylint/issues/6359 @only_required_for_messages("unsupported-binary-operation") def _visit_augassign(self, node: nodes.AugAssign) -> None: """Detect TypeErrors for augmented binary arithmetic operands.""" @@ -2109,13 +2109,13 @@ accessed. Python regular expressions are accepted.", confidence=INFERENCE, ) - if node.ctx == astroid.Load: + if node.ctx == astroid.Context.Load: supported_protocol = supports_getitem msg = "unsubscriptable-object" - elif node.ctx == astroid.Store: + elif node.ctx == astroid.Context.Store: supported_protocol = supports_setitem msg = "unsupported-assignment-operation" - elif node.ctx == astroid.Del: + elif node.ctx == astroid.Context.Del: supported_protocol = supports_delitem msg = "unsupported-delete-operation" |