mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-09 21:04:17 +00:00
Merge pull request #286 from pre-commit/fix_builtin_literals_check
Explicitly check for `ast.Name`
This commit is contained in:
commit
a66a33042a
2 changed files with 3 additions and 1 deletions
|
|
@ -30,7 +30,7 @@ class BuiltinTypeVisitor(ast.NodeVisitor):
|
||||||
return self.allow_dict_kwargs and (getattr(node, 'kwargs', None) or getattr(node, 'keywords', None))
|
return self.allow_dict_kwargs and (getattr(node, 'kwargs', None) or getattr(node, 'keywords', None))
|
||||||
|
|
||||||
def visit_Call(self, node):
|
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()`).
|
# Ignore functions that are object attributes (`foo.bar()`).
|
||||||
# Assume that if the user calls `builtins.list()`, they know what
|
# Assume that if the user calls `builtins.list()`, they know what
|
||||||
# they're doing.
|
# they're doing.
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ def visitor():
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
('expression', 'calls'),
|
('expression', 'calls'),
|
||||||
[
|
[
|
||||||
|
# see #285
|
||||||
|
('x[0]()', []),
|
||||||
# complex
|
# complex
|
||||||
("0j", []),
|
("0j", []),
|
||||||
("complex()", [BuiltinTypeCall('complex', 1, 0)]),
|
("complex()", [BuiltinTypeCall('complex', 1, 0)]),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue