@@ -26,36 +26,37 @@ class Call(NamedTuple):
2626class Visitor (ast .NodeVisitor ):
2727 def __init__ (
2828 self ,
29- ignore : Sequence [str ] | None = None ,
29+ ignore : set [str ],
3030 allow_dict_kwargs : bool = True ,
3131 ) -> None :
3232 self .builtin_type_calls : list [Call ] = []
33- self .ignore = set (ignore ) if ignore else set ()
3433 self .allow_dict_kwargs = allow_dict_kwargs
34+ self ._disallowed = BUILTIN_TYPES .keys () - ignore
3535
3636 def _check_dict_call (self , node : ast .Call ) -> bool :
3737 return self .allow_dict_kwargs and bool (node .keywords )
3838
3939 def visit_Call (self , node : ast .Call ) -> None :
40- if not isinstance ( node . func , ast . Name ):
40+ if (
4141 # Ignore functions that are object attributes (`foo.bar()`).
4242 # Assume that if the user calls `builtins.list()`, they know what
4343 # they're doing.
44- return
45- if node .func .id not in set ( BUILTIN_TYPES ). difference ( self .ignore ):
46- return
47- if node . func . id == 'dict' and self . _check_dict_call ( node ):
48- return
49- elif node . args :
50- return
51- self . builtin_type_calls . append (
52- Call ( node . func . id , node . lineno , node . col_offset ),
53- )
44+ isinstance ( node . func , ast . Name ) and
45+ node .func .id in self ._disallowed and
46+ ( node . func . id != 'dict' or not self . _check_dict_call ( node )) and
47+ not node . args
48+ ):
49+ self . builtin_type_calls . append (
50+ Call ( node . func . id , node . lineno , node . col_offset ),
51+ )
52+
53+ self . generic_visit ( node )
5454
5555
5656def check_file (
5757 filename : str ,
58- ignore : Sequence [str ] | None = None ,
58+ * ,
59+ ignore : set [str ],
5960 allow_dict_kwargs : bool = True ,
6061) -> list [Call ]:
6162 with open (filename , 'rb' ) as f :
0 commit comments