Merge pull request #286 from pre-commit/fix_builtin_literals_check

Explicitly check for `ast.Name`
This commit is contained in:
Anthony Sottile 2018-05-17 17:22:49 -07:00 committed by GitHub
commit a66a33042a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View file

@ -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.

View file

@ -16,6 +16,8 @@ def visitor():
@pytest.mark.parametrize(
('expression', 'calls'),
[
# see #285
('x[0]()', []),
# complex
("0j", []),
("complex()", [BuiltinTypeCall('complex', 1, 0)]),