Skip to content

Commit b4a283f

Browse files
Handle inference fail when calculating lenght of a node
Closes pylint-dev/pylint#4633
1 parent 366daef commit b4a283f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ What's New in astroid 2.6.2?
1212
============================
1313
Release date: TBA
1414

15+
* Fix a crash when the inference of the length of a node failed
1516

17+
Closes PyCQA/pylint#4633
1618

1719
What's New in astroid 2.6.1?
1820
============================

astroid/helpers.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,19 @@ def object_len(node, context=None):
290290
f"object of type '{node_type.pytype()}' has no len()"
291291
) from e
292292

293-
result_of_len = next(len_call.infer_call_result(node, context))
293+
inferred = len_call.infer_call_result(node, context)
294+
if inferred is util.Uninferable:
295+
raise InferenceError(node=node, context=context)
296+
result_of_len = next(inferred, None)
294297
if (
295298
isinstance(result_of_len, nodes.Const)
296299
and result_of_len.pytype() == "builtins.int"
297300
):
298301
return result_of_len.value
299-
if isinstance(result_of_len, bases.Instance) and result_of_len.is_subtype_of(
300-
"builtins.int"
302+
if (
303+
result_of_len is None
304+
or isinstance(result_of_len, bases.Instance)
305+
and result_of_len.is_subtype_of("builtins.int")
301306
):
302307
# Fake a result as we don't know the arguments of the instance call.
303308
return 0

0 commit comments

Comments
 (0)