Skip to content

Commit e4c87b5

Browse files
committed
Update CHANGES
1 parent f192d99 commit e4c87b5

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

CHANGES.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Changelog
66
2.0.2 (unreleased)
77
------------------
88

9-
- Nothing changed yet.
10-
9+
- Honor `--builtins` option from flake8 #73.
10+
[gforcada]
1111

1212
2.0.1 (2022-11-01)
1313
------------------

run_tests.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,26 @@
1010

1111
class FakeOptions:
1212
builtins_ignorelist = []
13+
builtins = None
1314

14-
def __init__(self, ignore_list=''):
15+
def __init__(self, ignore_list='', builtins=None):
1516
if ignore_list:
1617
self.builtins_ignorelist = ignore_list
18+
if builtins:
19+
self.builtins = builtins
1720

1821

19-
def check_code(source, expected_codes=None, ignore_list=None):
22+
def check_code(source, expected_codes=None, ignore_list=None, builtins=None):
2023
"""Check if the given source code generates the given flake8 errors
2124
2225
If `expected_codes` is a string is converted to a list,
2326
if it is not given, then it is expected to **not** generate any error.
2427
2528
If `ignore_list` is provided, it should be a list of names
2629
that will be ignored if found, as if they were a builtin.
30+
31+
If `builtins` is provided, it should be a list of names
32+
that will be reported if found, as if they were a builtin.
2733
"""
2834
if isinstance(expected_codes, str):
2935
expected_codes = [expected_codes]
@@ -33,7 +39,7 @@ def check_code(source, expected_codes=None, ignore_list=None):
3339
ignore_list = []
3440
tree = ast.parse(textwrap.dedent(source))
3541
checker = BuiltinsChecker(tree, '/home/script.py')
36-
checker.parse_options(FakeOptions(ignore_list=ignore_list))
42+
checker.parse_options(FakeOptions(ignore_list=ignore_list, builtins=builtins))
3743
return_statements = list(checker.run())
3844

3945
assert len(return_statements) == len(expected_codes)
@@ -212,6 +218,11 @@ def test_custom_ignored_names():
212218
check_code(source, ignore_list=('copyright',))
213219

214220

221+
def test_flake8_builtins():
222+
source = 'consider_this_builtin = 4'
223+
check_code(source, ['A001'], builtins=('consider_this_builtin',))
224+
225+
215226
def test_for_loop_variable():
216227
source = """
217228
for format in (1, 2, 3):

0 commit comments

Comments
 (0)