diff options
Diffstat (limited to 'astroid/helpers.py')
-rw-r--r-- | astroid/helpers.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/astroid/helpers.py b/astroid/helpers.py index be133b38..d94c9542 100644 --- a/astroid/helpers.py +++ b/astroid/helpers.py @@ -254,12 +254,16 @@ def object_len(node, context=None): return len(inferred_node.elts) if isinstance(inferred_node, nodes.Dict): return len(inferred_node.items) + + node_type = object_type(inferred_node, context=context) + if not node_type: + raise exceptions.InferenceError(node=node) + try: - node_type = object_type(inferred_node, context=context) len_call = next(node_type.igetattr("__len__", context=context)) except exceptions.AttributeInferenceError: raise exceptions.AstroidTypeError( - "object of type '{}' has no len()".format(len_call.pytype()) + "object of type '{}' has no len()".format(node_type.pytype()) ) result_of_len = next(len_call.infer_call_result(node, context)) @@ -268,6 +272,11 @@ def object_len(node, context=None): 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" + ): + # Fake a result as we don't know the arguments of the instance call. + return 0 raise exceptions.AstroidTypeError( "'{}' object cannot be interpreted as an integer".format(result_of_len) ) |