mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-14 08:24:46 +00:00
Rename methods on the new DecisionEngine
Rename `decision_for` to `more_specific_decision_for` and `should_report_error` to `decision_for`.
This commit is contained in:
parent
583fda7a70
commit
65107a5624
2 changed files with 13 additions and 42 deletions
|
|
@ -126,7 +126,7 @@ class DecisionEngine(object):
|
||||||
|
|
||||||
return Selected.Implicitly
|
return Selected.Implicitly
|
||||||
|
|
||||||
def decision_for(self, code):
|
def more_specific_decision_for(self, code):
|
||||||
# type: (Error) -> Decision
|
# type: (Error) -> Decision
|
||||||
select = find_first_match(code, self.all_selected)
|
select = find_first_match(code, self.all_selected)
|
||||||
extra_select = find_first_match(code, self.extended_selected)
|
extra_select = find_first_match(code, self.extended_selected)
|
||||||
|
|
@ -145,7 +145,7 @@ class DecisionEngine(object):
|
||||||
return Decision.Ignored
|
return Decision.Ignored
|
||||||
return Decision.Selected
|
return Decision.Selected
|
||||||
|
|
||||||
def should_report_error(self, code):
|
def decision_for(self, code):
|
||||||
# type: (str) -> Decision
|
# type: (str) -> Decision
|
||||||
"""Determine if the error code should be reported or ignored.
|
"""Determine if the error code should be reported or ignored.
|
||||||
|
|
||||||
|
|
@ -174,7 +174,7 @@ class DecisionEngine(object):
|
||||||
ignored is Ignored.Explicitly) or
|
ignored is Ignored.Explicitly) or
|
||||||
(selected is Ignored.Implicitly and
|
(selected is Ignored.Implicitly and
|
||||||
ignored is Selected.Implicitly)):
|
ignored is Selected.Implicitly)):
|
||||||
decision = self.decision_for(code)
|
decision = self.more_specific_decision_for(code)
|
||||||
elif (selected is Ignored.Implicitly or
|
elif (selected is Ignored.Implicitly or
|
||||||
ignored is Ignored.Explicitly):
|
ignored is Ignored.Explicitly):
|
||||||
decision = Decision.Ignored # pylint: disable=R0204
|
decision = Decision.Ignored # pylint: disable=R0204
|
||||||
|
|
@ -187,7 +187,7 @@ class DecisionEngine(object):
|
||||||
class StyleGuide(object):
|
class StyleGuide(object):
|
||||||
"""Manage a Flake8 user's style guide."""
|
"""Manage a Flake8 user's style guide."""
|
||||||
|
|
||||||
def __init__(self, options, listener_trie, formatter):
|
def __init__(self, options, listener_trie, formatter, decider=None):
|
||||||
"""Initialize our StyleGuide.
|
"""Initialize our StyleGuide.
|
||||||
|
|
||||||
.. todo:: Add parameter documentation.
|
.. todo:: Add parameter documentation.
|
||||||
|
|
@ -196,39 +196,9 @@ class StyleGuide(object):
|
||||||
self.listener = listener_trie
|
self.listener = listener_trie
|
||||||
self.formatter = formatter
|
self.formatter = formatter
|
||||||
self.stats = statistics.Statistics()
|
self.stats = statistics.Statistics()
|
||||||
self.decider = DecisionEngine(options)
|
self.decider = decider or DecisionEngine(options)
|
||||||
self._parsed_diff = {}
|
self._parsed_diff = {}
|
||||||
|
|
||||||
def is_user_selected(self, code):
|
|
||||||
# type: (str) -> Union[Selected, Ignored]
|
|
||||||
"""Determine if the code has been selected by the user.
|
|
||||||
|
|
||||||
:param str code:
|
|
||||||
The code for the check that has been run.
|
|
||||||
:returns:
|
|
||||||
Selected.Implicitly if the selected list is empty,
|
|
||||||
Selected.Explicitly if the selected list is not empty and a match
|
|
||||||
was found,
|
|
||||||
Ignored.Implicitly if the selected list is not empty but no match
|
|
||||||
was found.
|
|
||||||
"""
|
|
||||||
return self.decider.was_selected(code)
|
|
||||||
|
|
||||||
def is_user_ignored(self, code):
|
|
||||||
# type: (str) -> Union[Selected, Ignored]
|
|
||||||
"""Determine if the code has been ignored by the user.
|
|
||||||
|
|
||||||
:param str code:
|
|
||||||
The code for the check that has been run.
|
|
||||||
:returns:
|
|
||||||
Selected.Implicitly if the ignored list is empty,
|
|
||||||
Ignored.Explicitly if the ignored list is not empty and a match was
|
|
||||||
found,
|
|
||||||
Selected.Implicitly if the ignored list is not empty but no match
|
|
||||||
was found.
|
|
||||||
"""
|
|
||||||
return self.decider.was_ignored(code)
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def processing_file(self, filename):
|
def processing_file(self, filename):
|
||||||
"""Record the fact that we're processing the file's results."""
|
"""Record the fact that we're processing the file's results."""
|
||||||
|
|
@ -249,7 +219,7 @@ class StyleGuide(object):
|
||||||
:param str code:
|
:param str code:
|
||||||
The code for the check that has been run.
|
The code for the check that has been run.
|
||||||
"""
|
"""
|
||||||
return self.decider.should_report_error(code)
|
return self.decider.decision_for(code)
|
||||||
|
|
||||||
def is_inline_ignored(self, error):
|
def is_inline_ignored(self, error):
|
||||||
# type: (Error) -> bool
|
# type: (Error) -> bool
|
||||||
|
|
|
||||||
|
|
@ -118,12 +118,12 @@ def test_was_selected_excludes_errors(select_list, error_code):
|
||||||
(defaults.SELECT, defaults.IGNORE, 'E126', style_guide.Decision.Ignored),
|
(defaults.SELECT, defaults.IGNORE, 'E126', style_guide.Decision.Ignored),
|
||||||
(defaults.SELECT, defaults.IGNORE, 'W391', style_guide.Decision.Selected),
|
(defaults.SELECT, defaults.IGNORE, 'W391', style_guide.Decision.Selected),
|
||||||
])
|
])
|
||||||
def test_should_report_error(select_list, ignore_list, error_code, expected):
|
def test_decision_for(select_list, ignore_list, error_code, expected):
|
||||||
"""Verify we decide when to report an error."""
|
"""Verify we decide when to report an error."""
|
||||||
decider = style_guide.DecisionEngine(create_options(select=select_list,
|
decider = style_guide.DecisionEngine(create_options(select=select_list,
|
||||||
ignore=ignore_list))
|
ignore=ignore_list))
|
||||||
|
|
||||||
assert decider.should_report_error(error_code) is expected
|
assert decider.decision_for(error_code) is expected
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
@ -164,9 +164,10 @@ def test_should_report_error(select_list, ignore_list, error_code, expected):
|
||||||
style_guide.Decision.Selected),
|
style_guide.Decision.Selected),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_decision_for_logic(select, ignore, extend_select, enabled_extensions,
|
def test_more_specific_decision_for_logic(select, ignore, extend_select,
|
||||||
error_code, expected):
|
enabled_extensions, error_code,
|
||||||
"""Verify the complicated logic of DecisionEngine.decision_for."""
|
expected):
|
||||||
|
"""Verify the logic of DecisionEngine.more_specific_decision_for."""
|
||||||
decider = style_guide.DecisionEngine(
|
decider = style_guide.DecisionEngine(
|
||||||
create_options(
|
create_options(
|
||||||
select=select, ignore=ignore,
|
select=select, ignore=ignore,
|
||||||
|
|
@ -175,4 +176,4 @@ def test_decision_for_logic(select, ignore, extend_select, enabled_extensions,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert decider.decision_for(error_code) is expected
|
assert decider.more_specific_decision_for(error_code) is expected
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue