From e4c87b5cb48de15bf6a39457d9002d5d71c7be01 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Fri, 23 Dec 2022 00:39:50 +0100 Subject: [PATCH] Update CHANGES --- CHANGES.rst | 4 ++-- run_tests.py | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index ef9a6aa..a3fdb3b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,8 +6,8 @@ Changelog 2.0.2 (unreleased) ------------------ -- Nothing changed yet. - +- Honor `--builtins` option from flake8 #73. + [gforcada] 2.0.1 (2022-11-01) ------------------ diff --git a/run_tests.py b/run_tests.py index 637342f..f96297f 100644 --- a/run_tests.py +++ b/run_tests.py @@ -10,13 +10,16 @@ class FakeOptions: builtins_ignorelist = [] + builtins = None - def __init__(self, ignore_list=''): + def __init__(self, ignore_list='', builtins=None): if ignore_list: self.builtins_ignorelist = ignore_list + if builtins: + self.builtins = builtins -def check_code(source, expected_codes=None, ignore_list=None): +def check_code(source, expected_codes=None, ignore_list=None, builtins=None): """Check if the given source code generates the given flake8 errors If `expected_codes` is a string is converted to a list, @@ -24,6 +27,9 @@ def check_code(source, expected_codes=None, ignore_list=None): If `ignore_list` is provided, it should be a list of names that will be ignored if found, as if they were a builtin. + + If `builtins` is provided, it should be a list of names + that will be reported if found, as if they were a builtin. """ if isinstance(expected_codes, str): expected_codes = [expected_codes] @@ -33,7 +39,7 @@ def check_code(source, expected_codes=None, ignore_list=None): ignore_list = [] tree = ast.parse(textwrap.dedent(source)) checker = BuiltinsChecker(tree, '/home/script.py') - checker.parse_options(FakeOptions(ignore_list=ignore_list)) + checker.parse_options(FakeOptions(ignore_list=ignore_list, builtins=builtins)) return_statements = list(checker.run()) assert len(return_statements) == len(expected_codes) @@ -212,6 +218,11 @@ def test_custom_ignored_names(): check_code(source, ignore_list=('copyright',)) +def test_flake8_builtins(): + source = 'consider_this_builtin = 4' + check_code(source, ['A001'], builtins=('consider_this_builtin',)) + + def test_for_loop_variable(): source = """ for format in (1, 2, 3):