diff options
Diffstat (limited to 'pylint/checkers/typecheck.py')
-rw-r--r-- | pylint/checkers/typecheck.py | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 1a628f231..0298c81dc 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.""" @@ -125,7 +125,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 +158,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 +733,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 +1571,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: @@ -1685,9 +1692,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 +2022,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 +2030,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 +2116,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" |