From 7826795cb68dbc484f954d9a29101041ebf62119 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 23 Apr 2023 22:45:30 +0200 Subject: Fix `FunctionDef` isinstance checks (#8607) --- pylint/checkers/typecheck.py | 4 +++- pylint/checkers/utils.py | 5 +++-- pylint/checkers/variables.py | 5 +---- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'pylint') 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 -- cgit v1.2.1