diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2018-07-31 09:47:23 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-07-31 09:47:23 +0200 |
commit | f0044dd8b6d8d3d8f2e0b0291c105ac0dda38664 (patch) | |
tree | 2bf0f41ec8c93671b2e303b81db55b625911150f /astroid/helpers.py | |
parent | 2894a1a392ba564ad05ce695cfc35b11340049fc (diff) | |
download | astroid-git-f0044dd8b6d8d3d8f2e0b0291c105ac0dda38664.tar.gz |
infer_call_result can raise InferenceError so make sure to handle that for the call sites where it is used
infer_call_result started recently to raise InferenceError for objects for which it could not find any returns.
Previously it was silently raising a StopIteration, which was especially leaking when calling builtin methods.
Since it is after all an inference method, it is expected that it could raise an InferenceError rather than
returning nothing.
Close PyCQA/pylint#2350
Diffstat (limited to 'astroid/helpers.py')
-rw-r--r-- | astroid/helpers.py | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/astroid/helpers.py b/astroid/helpers.py index 2d79b621..d7a72338 100644 --- a/astroid/helpers.py +++ b/astroid/helpers.py @@ -256,11 +256,7 @@ def object_len(node, context=None): "object of type '{}' has no len()" .format(len_call.pytype())) - try: - result_of_len = next(len_call.infer_call_result(node, context)) - # Remove StopIteration catch when #507 is fixed - except StopIteration: - raise exceptions.InferenceError(node=node) + result_of_len = next(len_call.infer_call_result(node, context)) if isinstance(result_of_len, nodes.Const) and result_of_len.pytype() == "builtins.int": return result_of_len.value raise exceptions.AstroidTypeError( |