mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-17 17:39:53 +00:00
Pull decision making out of decision_for
Also, this further highlights why naming methods is so hard. I can't think of a better name for 'more_specific_decision_for' that isn't wildly long and unnecessarily verbose.
This commit is contained in:
parent
3921afccff
commit
86e1fb6e64
1 changed files with 28 additions and 22 deletions
|
|
@ -240,21 +240,8 @@ class DecisionEngine(object):
|
||||||
return Decision.Ignored
|
return Decision.Ignored
|
||||||
return Decision.Selected
|
return Decision.Selected
|
||||||
|
|
||||||
def decision_for(self, code):
|
def make_decision(self, code):
|
||||||
# type: (str) -> Decision
|
"""Decide if code should be ignored or selected."""
|
||||||
"""Determine if the error code should be reported or ignored.
|
|
||||||
|
|
||||||
This method only cares about the select and ignore rules as specified
|
|
||||||
by the user in their configuration files and command-line flags.
|
|
||||||
|
|
||||||
This method does not look at whether the specific line is being
|
|
||||||
ignored in the file itself.
|
|
||||||
|
|
||||||
:param str code:
|
|
||||||
The code for the check that has been run.
|
|
||||||
"""
|
|
||||||
decision = self.cache.get(code)
|
|
||||||
if decision is None:
|
|
||||||
LOG.debug('Deciding if "%s" should be reported', code)
|
LOG.debug('Deciding if "%s" should be reported', code)
|
||||||
selected = self.was_selected(code)
|
selected = self.was_selected(code)
|
||||||
ignored = self.was_ignored(code)
|
ignored = self.was_ignored(code)
|
||||||
|
|
@ -273,7 +260,26 @@ class DecisionEngine(object):
|
||||||
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
|
||||||
|
return decision
|
||||||
|
|
||||||
|
def decision_for(self, code):
|
||||||
|
# type: (str) -> Decision
|
||||||
|
"""Return the decision for a specific code.
|
||||||
|
|
||||||
|
This method caches the decisions for codes to avoid retracing the same
|
||||||
|
logic over and over again. We only care about the select and ignore
|
||||||
|
rules as specified by the user in their configuration files and
|
||||||
|
command-line flags.
|
||||||
|
|
||||||
|
This method does not look at whether the specific line is being
|
||||||
|
ignored in the file itself.
|
||||||
|
|
||||||
|
:param str code:
|
||||||
|
The code for the check that has been run.
|
||||||
|
"""
|
||||||
|
decision = self.cache.get(code)
|
||||||
|
if decision is None:
|
||||||
|
decision = self.make_decision(code)
|
||||||
self.cache[code] = decision
|
self.cache[code] = decision
|
||||||
LOG.debug('"%s" will be "%s"', code, decision)
|
LOG.debug('"%s" will be "%s"', code, decision)
|
||||||
return decision
|
return decision
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue