From b0cad5530eac3ebe007141aae7295e198956a3b1 Mon Sep 17 00:00:00 2001 From: Max R Date: Sun, 31 Jul 2022 07:37:54 -0400 Subject: [PATCH] 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 --- src/flake8/style_guide.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/flake8/style_guide.py b/src/flake8/style_guide.py index 05044133..b7115a0c 100644 --- a/src/flake8/style_guide.py +++ b/src/flake8/style_guide.py @@ -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(