From 54ec6fd4b6971f6d1022259a5b3eeb0f15e12bdb Mon Sep 17 00:00:00 2001 From: Alphadelta14 Date: Wed, 14 Apr 2021 16:27:03 -0400 Subject: [PATCH 1/4] Select last inferred value for usage --- pylint/checkers/utils.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index 0267dfd582..a0c191f212 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -1219,14 +1219,8 @@ def safe_infer( inferred_type = _get_python_type_of_node(inferred) if inferred_type not in inferred_types: return None # If there is ambiguity on the inferred node. - if ( - isinstance(inferred, nodes.FunctionDef) - and inferred.args.args is not None - and isinstance(value, nodes.FunctionDef) - and value.args.args is not None - and len(inferred.args.args) != len(value.args.args) - ): - return None # Different number of arguments indicates ambiguity + # For multiple inferences of the same type, select the last one + value = inferred except astroid.InferenceError: return None # There is some kind of ambiguity except StopIteration: From 186cae46d717f30033d132202e48e34f4c5abb6b Mon Sep 17 00:00:00 2001 From: Alphadelta14 Date: Mon, 12 Jul 2021 11:38:38 -0400 Subject: [PATCH 2/4] Do not explicitly require https://github.com/PyCQA/astroid/pull/1097 --- pylint/checkers/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index a0c191f212..85beb02609 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -1219,6 +1219,15 @@ def safe_infer( inferred_type = _get_python_type_of_node(inferred) if inferred_type not in inferred_types: return None # If there is ambiguity on the inferred node. + if isinstance(inferred, astroid.objects.PartialFunction): + # Before https://github.com/PyCQA/astroid/pull/1097, + # partials got placed into the same scope as parents + # even though they usually have different names and may be + # defined elsewhere. + # We do not select the later value in this case. + # This condition can be removed if astroid#1097 is + # guaranteed to be present. + continue # For multiple inferences of the same type, select the last one value = inferred except astroid.InferenceError: From 6128fb704b8d1312072d794cd3bf868715fdd64c Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sun, 3 Apr 2022 13:48:43 +0200 Subject: [PATCH 3/4] Update pylint/checkers/utils.py --- pylint/checkers/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index 85beb02609..cc42a86efe 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -1219,6 +1219,14 @@ def safe_infer( inferred_type = _get_python_type_of_node(inferred) if inferred_type not in inferred_types: return None # If there is ambiguity on the inferred node. + if ( + isinstance(inferred, nodes.FunctionDef) + and inferred.args.args is not None + and isinstance(value, nodes.FunctionDef) + and value.args.args is not None + and len(inferred.args.args) != len(value.args.args) + ): + return None # Different number of arguments indicates ambiguity if isinstance(inferred, astroid.objects.PartialFunction): # Before https://github.com/PyCQA/astroid/pull/1097, # partials got placed into the same scope as parents From 4dfb89df267ec26758753094f90e5bd6edb54cc4 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sun, 3 Apr 2022 13:54:09 +0200 Subject: [PATCH 4/4] Update pylint/checkers/utils.py --- pylint/checkers/utils.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index cc42a86efe..a19cde7a7e 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -1227,15 +1227,6 @@ def safe_infer( and len(inferred.args.args) != len(value.args.args) ): return None # Different number of arguments indicates ambiguity - if isinstance(inferred, astroid.objects.PartialFunction): - # Before https://github.com/PyCQA/astroid/pull/1097, - # partials got placed into the same scope as parents - # even though they usually have different names and may be - # defined elsewhere. - # We do not select the later value in this case. - # This condition can be removed if astroid#1097 is - # guaranteed to be present. - continue # For multiple inferences of the same type, select the last one value = inferred except astroid.InferenceError: