summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2017-06-04 14:50:20 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2017-06-04 14:50:20 -0500
commit86e1fb6e64ecc76d8c94416a92686d56d0fe5978 (patch)
tree6f31f55f4dafc09a0f8ced9fd478f4bdd13b485e /src
parent3921afccff66702101e3e8dd99bc184eed77e962 (diff)
downloadflake8-86e1fb6e64ecc76d8c94416a92686d56d0fe5978.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/flake8/style_guide.py50
1 files changed, 28 insertions, 22 deletions
diff --git a/src/flake8/style_guide.py b/src/flake8/style_guide.py
index 124c7d5..f47a628 100644
--- a/src/flake8/style_guide.py
+++ b/src/flake8/style_guide.py
@@ -240,12 +240,36 @@ class DecisionEngine(object):
return Decision.Ignored
return Decision.Selected
+ def make_decision(self, code):
+ """Decide if code should be ignored or selected."""
+ LOG.debug('Deciding if "%s" should be reported', code)
+ selected = self.was_selected(code)
+ ignored = self.was_ignored(code)
+ LOG.debug('The user configured "%s" to be "%s", "%s"',
+ code, selected, ignored)
+
+ if ((selected is Selected.Explicitly or
+ selected is Selected.Implicitly) and
+ ignored is Selected.Implicitly):
+ decision = Decision.Selected
+ elif ((selected is Selected.Explicitly and
+ ignored is Ignored.Explicitly) or
+ (selected is Ignored.Implicitly and
+ ignored is Selected.Implicitly)):
+ decision = self.more_specific_decision_for(code)
+ elif (selected is Ignored.Implicitly or
+ ignored is Ignored.Explicitly):
+ decision = Decision.Ignored # pylint: disable=R0204
+ return decision
+
def decision_for(self, code):
# type: (str) -> Decision
- """Determine if the error code should be reported or ignored.
+ """Return the decision for a specific code.
- 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 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.
@@ -255,25 +279,7 @@ class DecisionEngine(object):
"""
decision = self.cache.get(code)
if decision is None:
- LOG.debug('Deciding if "%s" should be reported', code)
- selected = self.was_selected(code)
- ignored = self.was_ignored(code)
- LOG.debug('The user configured "%s" to be "%s", "%s"',
- code, selected, ignored)
-
- if ((selected is Selected.Explicitly or
- selected is Selected.Implicitly) and
- ignored is Selected.Implicitly):
- decision = Decision.Selected
- elif ((selected is Selected.Explicitly and
- ignored is Ignored.Explicitly) or
- (selected is Ignored.Implicitly and
- ignored is Selected.Implicitly)):
- decision = self.more_specific_decision_for(code)
- elif (selected is Ignored.Implicitly or
- ignored is Ignored.Explicitly):
- decision = Decision.Ignored # pylint: disable=R0204
-
+ decision = self.make_decision(code)
self.cache[code] = decision
LOG.debug('"%s" will be "%s"', code, decision)
return decision