Skip to content

Commit

Permalink
Handle inference fail when calculating lenght of a node
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Jun 30, 2021
1 parent 366daef commit 7c6a1e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ChangeLog
Expand Up @@ -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?
============================
Expand Down
5 changes: 4 additions & 1 deletion astroid/helpers.py
Expand Up @@ -290,7 +290,10 @@ 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)
if (
isinstance(result_of_len, nodes.Const)
and result_of_len.pytype() == "builtins.int"
Expand Down

0 comments on commit 7c6a1e7

Please sign in to comment.