Skip to content

Commit 7826795

Browse files
authored
Fix FunctionDef isinstance checks (#8607)
1 parent 34d3ad7 commit 7826795

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

pylint/checkers/typecheck.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,9 @@ def _no_context_variadic(
733733
else:
734734
inferred_statement = inferred.statement(future=True)
735735

736-
if not length and isinstance(inferred_statement, nodes.Lambda):
736+
if not length and isinstance(
737+
inferred_statement, (nodes.Lambda, nodes.FunctionDef)
738+
):
737739
is_in_starred_context = _has_parent_of_type(node, variadic_type, statement)
738740
used_as_starred_argument = any(
739741
variadic.value == name or variadic.value.parent_of(name)

pylint/checkers/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,10 @@ def is_defined_before(var_node: nodes.Name) -> bool:
356356
if defnode is None:
357357
continue
358358
defnode_scope = defnode.scope()
359-
if isinstance(defnode_scope, (*COMP_NODE_TYPES, nodes.Lambda)):
359+
if isinstance(
360+
defnode_scope, (*COMP_NODE_TYPES, nodes.Lambda, nodes.FunctionDef)
361+
):
360362
# Avoid the case where var_node_scope is a nested function
361-
# FunctionDef is a Lambda until https://github.com/pylint-dev/astroid/issues/291
362363
if isinstance(defnode_scope, nodes.FunctionDef):
363364
var_node_scope = var_node.scope()
364365
if var_node_scope is not defnode_scope and isinstance(

pylint/checkers/variables.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,10 +2497,7 @@ def _loopvar_name(self, node: astroid.Name) -> None:
24972497
# the usage is safe because the function will not be defined either if
24982498
# the variable is not defined.
24992499
scope = node.scope()
2500-
# FunctionDef subclasses Lambda due to a curious ontology. Check both.
2501-
# See https://github.com/pylint-dev/astroid/issues/291
2502-
# TODO: Revisit when astroid 3.0 includes the change
2503-
if isinstance(scope, nodes.Lambda) and any(
2500+
if isinstance(scope, (nodes.Lambda, nodes.FunctionDef)) and any(
25042501
asmt.scope().parent_of(scope) for asmt in astmts
25052502
):
25062503
return

0 commit comments

Comments
 (0)