From b4a283f388f495df76489dd6226056953153138e Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Wed, 30 Jun 2021 11:08:14 +0200 Subject: Handle inference fail when calculating lenght of a node Closes https://github.com/PyCQA/pylint/issues/4633 --- ChangeLog | 2 ++ astroid/helpers.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5abe8391..3da3ef50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,7 +12,9 @@ What's New in astroid 2.6.2? ============================ Release date: TBA +* Fix a crash when the inference of the length of a node failed + Closes PyCQA/pylint#4633 What's New in astroid 2.6.1? ============================ diff --git a/astroid/helpers.py b/astroid/helpers.py index c32b5e0f..3b6ddee2 100644 --- a/astroid/helpers.py +++ b/astroid/helpers.py @@ -290,14 +290,19 @@ def object_len(node, context=None): f"object of type '{node_type.pytype()}' has no len()" ) from e - result_of_len = next(len_call.infer_call_result(node, context)) + inferred = len_call.infer_call_result(node, context) + if inferred is util.Uninferable: + raise InferenceError(node=node, context=context) + result_of_len = next(inferred, None) if ( isinstance(result_of_len, nodes.Const) and result_of_len.pytype() == "builtins.int" ): return result_of_len.value - if isinstance(result_of_len, bases.Instance) and result_of_len.is_subtype_of( - "builtins.int" + if ( + result_of_len is None + or isinstance(result_of_len, bases.Instance) + and result_of_len.is_subtype_of("builtins.int") ): # Fake a result as we don't know the arguments of the instance call. return 0 -- cgit v1.2.1