Skip to content

Commit

Permalink
Remove needless sort in _style_guide_for
Browse files Browse the repository at this point in the history
We are always returning the last element so a 'max' operation is sufficient instead of sorting. Note the old code did not handle an empty list so this change doesn't either
  • Loading branch information
mxr committed Jul 31, 2022
1 parent c7c6218 commit b0cad55
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/flake8/style_guide.py
Expand Up @@ -254,13 +254,10 @@ def populate_style_guides_with(

def _style_guide_for(self, filename: str) -> "StyleGuide":
"""Find the StyleGuide for the filename in particular."""
guides = sorted(
return max(
(g for g in self.style_guides if g.applies_to(filename)),
key=lambda g: len(g.filename or ""),
)
if len(guides) > 1:
return guides[-1]
return guides[0]

@contextlib.contextmanager
def processing_file(
Expand Down

0 comments on commit b0cad55

Please sign in to comment.