From df93509aed538881f56edb527de8f6f8bb25b998 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 17 May 2018 17:14:25 -0700 Subject: [PATCH] Explicitly check for `ast.Name` --- pre_commit_hooks/check_builtin_literals.py | 2 +- tests/check_builtin_literals_test.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pre_commit_hooks/check_builtin_literals.py b/pre_commit_hooks/check_builtin_literals.py index c4ac969..b7f0c00 100644 --- a/pre_commit_hooks/check_builtin_literals.py +++ b/pre_commit_hooks/check_builtin_literals.py @@ -30,7 +30,7 @@ class BuiltinTypeVisitor(ast.NodeVisitor): return self.allow_dict_kwargs and (getattr(node, 'kwargs', None) or getattr(node, 'keywords', None)) def visit_Call(self, node): - if isinstance(node.func, ast.Attribute): + if not isinstance(node.func, ast.Name): # Ignore functions that are object attributes (`foo.bar()`). # Assume that if the user calls `builtins.list()`, they know what # they're doing. diff --git a/tests/check_builtin_literals_test.py b/tests/check_builtin_literals_test.py index 13f896a..5ab162e 100644 --- a/tests/check_builtin_literals_test.py +++ b/tests/check_builtin_literals_test.py @@ -16,6 +16,8 @@ def visitor(): @pytest.mark.parametrize( ('expression', 'calls'), [ + # see #285 + ('x[0]()', []), # complex ("0j", []), ("complex()", [BuiltinTypeCall('complex', 1, 0)]),