diff options
author | Bryce Guinta <bryce.paul.guinta@gmail.com> | 2018-03-15 20:18:21 -0600 |
---|---|---|
committer | Bryce Guinta <bryce.paul.guinta@gmail.com> | 2018-03-15 19:46:42 -0700 |
commit | 5d21b2005b06e3a353dd64aa16c6db5628058ed8 (patch) | |
tree | b5161b0bc25a873135aecad4092a56670b5e5365 /astroid/helpers.py | |
parent | 3c1731b8b4ca3eca93e3686221de24d60cb6c52f (diff) | |
download | astroid-git-5d21b2005b06e3a353dd64aa16c6db5628058ed8.tar.gz |
Fix len builtin for instances of str or bytes
A ClassDef of str or bytes may have the same qname as a Const value of str or bytes
causing an AttributeError in len builtin inference
Diffstat (limited to 'astroid/helpers.py')
-rw-r--r-- | astroid/helpers.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/astroid/helpers.py b/astroid/helpers.py index f55792b6..14148ad8 100644 --- a/astroid/helpers.py +++ b/astroid/helpers.py @@ -240,7 +240,8 @@ def object_len(node, context=None): inferred_node = safe_infer(node, context=context) if inferred_node is None or inferred_node is util.Uninferable: raise exceptions.InferenceError(node=node) - if inferred_node.qname() in ('builtins.str', 'builtins.bytes'): + if (isinstance(inferred_node, nodes.Const) and + isinstance(inferred_node.value, (bytes, str))): return len(inferred_node.value) if isinstance(inferred_node, (nodes.List, nodes.Set, nodes.Tuple, FrozenSet)): return len(inferred_node.elts) |