Merge pull request #1516 from asottile/simplify

simplify a bit of code in style_guide.py
This commit is contained in:
Anthony Sottile 2022-01-05 22:00:39 -05:00 committed by GitHub
commit 3768a44e76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -78,14 +78,6 @@ class DecisionEngine:
).union(options.extended_default_ignore) ).union(options.extended_default_ignore)
self.using_default_select = set(self.selected) == set(defaults.SELECT) self.using_default_select = set(self.selected) == set(defaults.SELECT)
def _in_all_selected(self, code: str) -> bool:
return bool(self.all_selected) and code.startswith(self.all_selected)
def _in_extended_selected(self, code: str) -> bool:
return bool(self.extended_selected) and code.startswith(
self.extended_selected
)
def was_selected(self, code: str) -> Union[Selected, Ignored]: def was_selected(self, code: str) -> Union[Selected, Ignored]:
"""Determine if the code has been selected by the user. """Determine if the code has been selected by the user.
@ -97,10 +89,10 @@ class DecisionEngine:
Ignored.Implicitly if the selected list is not empty but no match Ignored.Implicitly if the selected list is not empty but no match
was found. was found.
""" """
if self._in_all_selected(code): if code.startswith(self.all_selected):
return Selected.Explicitly return Selected.Explicitly
if not self.all_selected and self._in_extended_selected(code): if not self.all_selected and code.startswith(self.extended_selected):
# If it was not explicitly selected, it may have been implicitly # If it was not explicitly selected, it may have been implicitly
# selected because the check comes from a plugin that is enabled by # selected because the check comes from a plugin that is enabled by
# default # default
@ -120,7 +112,7 @@ class DecisionEngine:
Selected.Implicitly if the ignored list is not empty but no match Selected.Implicitly if the ignored list is not empty but no match
was found. was found.
""" """
if self.ignored and code.startswith(self.ignored): if code.startswith(self.ignored):
return Ignored.Explicitly return Ignored.Explicitly
return Selected.Implicitly return Selected.Implicitly
@ -444,8 +436,7 @@ class StyleGuide:
""" """
disable_noqa = self.options.disable_noqa disable_noqa = self.options.disable_noqa
# NOTE(sigmavirus24): Apparently we're provided with 0-indexed column # NOTE(sigmavirus24): Apparently we're provided with 0-indexed column
# numbers so we have to offset that here. Also, if a SyntaxError is # numbers so we have to offset that here.
# caught, column_number may be None.
if not column_number: if not column_number:
column_number = 0 column_number = 0
error = Violation( error = Violation(
@ -491,7 +482,6 @@ def find_first_match(
startswith = error_code.startswith startswith = error_code.startswith
for code in code_list: for code in code_list:
if startswith(code): if startswith(code):
break return code
else: else:
return None return None
return code