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
This commit is contained in:
Max R 2022-07-31 07:37:54 -04:00 committed by GitHub
parent c7c6218e58
commit b0cad5530e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -254,13 +254,10 @@ class StyleGuideManager:
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(