Skip to content

Commit af2a709

Browse files
gsingh93gforcada
authored andcommitted
Add --builtins-whitelist option
1 parent 552face commit af2a709

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

flake8_builtins.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
}
1414

1515

16-
BUILTINS = [a[0] for a in inspect.getmembers(builtins) if a[0] not in WHITE_LIST]
16+
# Will be initialized in `BuiltinsChecker.parse_options`
17+
BUILTINS = None
1718

1819
if sys.version_info >= (3, 8):
1920
NamedExpr = ast.NamedExpr
@@ -32,6 +33,25 @@ def __init__(self, tree, filename):
3233
self.tree = tree
3334
self.filename = filename
3435

36+
def add_options(option_manager):
37+
option_manager.add_option(
38+
'--builtins-whitelist',
39+
metavar='builtins',
40+
parse_from_config=True,
41+
comma_separated_list=True,
42+
help='A comma separated list of builtins to skip checking',
43+
)
44+
45+
def parse_options(option_manager, options, args):
46+
global BUILTINS
47+
48+
if options.builtins_whitelist is not None:
49+
WHITE_LIST.update(options.builtins_whitelist)
50+
51+
BUILTINS = [
52+
a[0] for a in inspect.getmembers(builtins) if a[0] not in WHITE_LIST
53+
]
54+
3555
def run(self):
3656
tree = self.tree
3757

0 commit comments

Comments
 (0)