Skip to content

Commit b0cad55

Browse files
authored
Remove needless sort in _style_guide_for
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
1 parent c7c6218 commit b0cad55

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

src/flake8/style_guide.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,10 @@ def populate_style_guides_with(
254254

255255
def _style_guide_for(self, filename: str) -> "StyleGuide":
256256
"""Find the StyleGuide for the filename in particular."""
257-
guides = sorted(
257+
return max(
258258
(g for g in self.style_guides if g.applies_to(filename)),
259259
key=lambda g: len(g.filename or ""),
260260
)
261-
if len(guides) > 1:
262-
return guides[-1]
263-
return guides[0]
264261

265262
@contextlib.contextmanager
266263
def processing_file(

0 commit comments

Comments
 (0)