Skip to content

Commit

Permalink
Fix bug for plugins using extend_default_ignore
Browse files Browse the repository at this point in the history
Since Flake8 3.0 we've had the ability for plugins to use
`extend_default_ignore` to register codes they want disabled by default.
This, however, was a permanent disabling unfortunately. Our code didn't
have a way of understanding that this new set of `ignore` codes was
actually the 'default' set for that run. Much like the
extended_select_list, we now attach extended_ignore_list to be able to
confidently determine if the ignore we get in the DecisionEngine is
actually the Default Ignore list and what plugins what us to ignore by
default.

Refs PyCQA/pep8-naming#157
  • Loading branch information
sigmavirus24 authored and asottile committed Apr 16, 2021
1 parent 434c108 commit e3313e0
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 25 deletions.
4 changes: 4 additions & 0 deletions src/flake8/options/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def aggregate_options(
# Extend the default ignore value with the extended default ignore list,
# registered by plugins.
extended_default_ignore = manager.extended_default_ignore.copy()
# Let's store our extended default ignore for use by the decision engine
default_values.extended_default_ignore = (
manager.extended_default_ignore.copy()
)
LOG.debug(
"Extended default ignore list: %s", list(extended_default_ignore)
)
Expand Down
4 changes: 3 additions & 1 deletion src/flake8/style_guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ def __init__(self, options): # type: (argparse.Namespace) -> None
reverse=True,
)
)
self.using_default_ignore = set(self.ignored) == set(defaults.IGNORE)
self.using_default_ignore = set(self.ignored) == set(
defaults.IGNORE
).union(options.extended_default_ignore)
self.using_default_select = set(self.selected) == set(defaults.SELECT)

def _in_all_selected(self, code): # type: (str) -> bool
Expand Down
87 changes: 63 additions & 24 deletions tests/unit/test_decision_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
def create_options(**kwargs):
"""Create and return an instance of argparse.Namespace."""
kwargs.setdefault('select', [])
kwargs.setdefault('extended_default_ignore', [])
kwargs.setdefault('extended_default_select', [])
kwargs.setdefault('ignore', [])
kwargs.setdefault('extend_ignore', [])
Expand Down Expand Up @@ -144,54 +145,92 @@ def test_decision_for(select_list, ignore_list, extend_ignore, error_code,


@pytest.mark.parametrize(
'select,ignore,extend_select,enabled_extensions,error_code,expected', [
(defaults.SELECT, [], ['I1'], [], 'I100',
'select,ignore,extended_default_ignore,extend_select,enabled_extensions,'
'error_code,expected', [
(defaults.SELECT, [], [], ['I1'], [], 'I100',
style_guide.Decision.Selected),
(defaults.SELECT, [], ['I1'], [], 'I201',
(defaults.SELECT, [], [], ['I1'], [], 'I201',
style_guide.Decision.Ignored),
(defaults.SELECT, ['I2'], ['I1'], [], 'I101',
(defaults.SELECT, ['I2'], [], ['I1'], [], 'I101',
style_guide.Decision.Selected),
(defaults.SELECT, ['I2'], ['I1'], [], 'I201',
(defaults.SELECT, ['I2'], [], ['I1'], [], 'I201',
style_guide.Decision.Ignored),
(defaults.SELECT, ['I1'], ['I10'], [], 'I101',
(defaults.SELECT, ['I1'], [], ['I10'], [], 'I101',
style_guide.Decision.Selected),
(defaults.SELECT, ['I10'], ['I1'], [], 'I101',
(defaults.SELECT, ['I10'], [], ['I1'], [], 'I101',
style_guide.Decision.Ignored),
(defaults.SELECT, [], [], ['U4'], 'U401',
(defaults.SELECT, [], [], [], ['U4'], 'U401',
style_guide.Decision.Selected),
(defaults.SELECT, ['U401'], [], ['U4'], 'U401',
(defaults.SELECT, ['U401'], [], [], ['U4'], 'U401',
style_guide.Decision.Ignored),
(defaults.SELECT, ['U401'], [], ['U4'], 'U402',
(defaults.SELECT, ['U401'], [], [], ['U4'], 'U402',
style_guide.Decision.Selected),
(['E', 'W'], ['E13'], [], [], 'E131', style_guide.Decision.Ignored),
(['E', 'W'], ['E13'], [], [], 'E126', style_guide.Decision.Selected),
(['E2'], ['E21'], [], [], 'E221', style_guide.Decision.Selected),
(['E2'], ['E21'], [], [], 'E212', style_guide.Decision.Ignored),
(['F', 'W'], ['C90'], ['I1'], [], 'C901',
(
['E', 'W'],
['E13'],
[],
[],
[],
'E131',
style_guide.Decision.Ignored,
),
(
['E', 'W'],
['E13'],
[],
[],
[],
'E126',
style_guide.Decision.Selected,
),
(['E2'], ['E21'], [], [], [], 'E221', style_guide.Decision.Selected),
(['E2'], ['E21'], [], [], [], 'E212', style_guide.Decision.Ignored),
(['F', 'W'], ['C90'], [], ['I1'], [], 'C901',
style_guide.Decision.Ignored),
(['E', 'W'], ['C'], [], [], 'E131',
(['E', 'W'], ['C'], [], [], [], 'E131',
style_guide.Decision.Selected),
(defaults.SELECT, defaults.IGNORE, [], ['I'], 'I101',
(defaults.SELECT, defaults.IGNORE, [], [], ['I'], 'I101',
style_guide.Decision.Selected),
(defaults.SELECT, defaults.IGNORE, ['G'], ['I'], 'G101',
(defaults.SELECT, defaults.IGNORE, [], ['G'], ['I'], 'G101',
style_guide.Decision.Selected),
(defaults.SELECT, ['G1'], ['G'], ['I'], 'G101',
(defaults.SELECT, ['G1'], [], ['G'], ['I'], 'G101',
style_guide.Decision.Ignored),
(defaults.SELECT, ['E126'], [], ['I'], 'I101',
(defaults.SELECT, ['E126'], [], [], ['I'], 'I101',
style_guide.Decision.Selected),
(['E', 'W'], defaults.IGNORE, ['I'], [], 'I101',
(['E', 'W'], defaults.IGNORE, [], ['I'], [], 'I101',
style_guide.Decision.Ignored),
(
["E", "W", "I101"],
defaults.IGNORE + ("I101",),
["I101"],
[],
[],
"I101",
style_guide.Decision.Selected,
),
(
["E", "W"],
defaults.IGNORE + ("I101",),
["I101"],
[],
[],
"I101",
style_guide.Decision.Ignored,
),
# TODO(sigmavirus24) Figure out how to exercise the final catch-all
# return statement
]
)
def test_more_specific_decision_for_logic(select, ignore, extend_select,
enabled_extensions, error_code,
expected):
def test_more_specific_decision_for_logic(
select, ignore, extended_default_ignore, extend_select,
enabled_extensions, error_code,
expected,
):
"""Verify the logic of DecisionEngine.more_specific_decision_for."""
decider = style_guide.DecisionEngine(
create_options(
select=select, ignore=ignore,
extended_default_ignore=extended_default_ignore,
extended_default_select=extend_select,
enable_extensions=enabled_extensions,
),
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_style_guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
def create_options(**kwargs):
"""Create and return an instance of argparse.Namespace."""
kwargs.setdefault('select', [])
kwargs.setdefault('extended_default_ignore', [])
kwargs.setdefault('extended_default_select', [])
kwargs.setdefault('ignore', [])
kwargs.setdefault('extend_ignore', [])
Expand Down

0 comments on commit e3313e0

Please sign in to comment.