summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Mueller <30130371+cdce8p@users.noreply.github.com>2023-04-23 22:45:30 +0200
committerGitHub <noreply@github.com>2023-04-23 22:45:30 +0200
commit7826795cb68dbc484f954d9a29101041ebf62119 (patch)
tree1871a819d7885645a135bb24278450273d2a486e
parent34d3ad71c9cf9d29cc2ee91531b0b9b101a999d7 (diff)
downloadpylint-git-7826795cb68dbc484f954d9a29101041ebf62119.tar.gz
Fix `FunctionDef` isinstance checks (#8607)
-rw-r--r--pylint/checkers/typecheck.py4
-rw-r--r--pylint/checkers/utils.py5
-rw-r--r--pylint/checkers/variables.py5
3 files changed, 7 insertions, 7 deletions
diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py
index 19bdb39aa..1c58efadb 100644
--- a/pylint/checkers/typecheck.py
+++ b/pylint/checkers/typecheck.py
@@ -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)
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index c76c767aa..95a0e7b7b 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -356,9 +356,10 @@ def is_defined_before(var_node: nodes.Name) -> bool:
if defnode is None:
continue
defnode_scope = defnode.scope()
- if isinstance(defnode_scope, (*COMP_NODE_TYPES, nodes.Lambda)):
+ if isinstance(
+ defnode_scope, (*COMP_NODE_TYPES, nodes.Lambda, nodes.FunctionDef)
+ ):
# Avoid the case where var_node_scope is a nested function
- # FunctionDef is a Lambda until https://github.com/pylint-dev/astroid/issues/291
if isinstance(defnode_scope, nodes.FunctionDef):
var_node_scope = var_node.scope()
if var_node_scope is not defnode_scope and isinstance(
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index 254ef5f5a..e1b82bb41 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -2497,10 +2497,7 @@ class VariablesChecker(BaseChecker):
# the usage is safe because the function will not be defined either if
# the variable is not defined.
scope = node.scope()
- # FunctionDef subclasses Lambda due to a curious ontology. Check both.
- # See https://github.com/pylint-dev/astroid/issues/291
- # TODO: Revisit when astroid 3.0 includes the change
- if isinstance(scope, nodes.Lambda) and any(
+ if isinstance(scope, (nodes.Lambda, nodes.FunctionDef)) and any(
asmt.scope().parent_of(scope) for asmt in astmts
):
return