From b8b29dc3ad57f56dc44482ef06d03dad7fcde131 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 4 Jan 2023 22:25:17 -0800 Subject: [PATCH] =?UTF-8?q?ruff:=20Fix=20SIM110=20Use=20`return=20any(?= =?UTF-8?q?=E2=80=A6)`=20instead=20of=20`for`=20loop.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Anders Kaseorg --- zerver/data_import/mattermost.py | 13 +++++-------- zerver/lib/markdown/__init__.py | 5 +---- zerver/lib/narrow.py | 15 ++++++--------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/zerver/data_import/mattermost.py b/zerver/data_import/mattermost.py index 53e4fc463d..e2f2030828 100644 --- a/zerver/data_import/mattermost.py +++ b/zerver/data_import/mattermost.py @@ -65,10 +65,10 @@ def process_user( def is_team_admin(user_dict: Dict[str, Any]) -> bool: if user_dict["teams"] is None: return False - for team in user_dict["teams"]: - if team["name"] == team_name and "team_admin" in team["roles"]: - return True - return False + return any( + team["name"] == team_name and "team_admin" in team["roles"] + for team in user_dict["teams"] + ) def get_full_name(user_dict: Dict[str, Any]) -> str: full_name = "{} {}".format(user_dict["first_name"], user_dict["last_name"]) @@ -809,10 +809,7 @@ def check_user_in_team(user: Dict[str, Any], team_name: str) -> bool: if user["teams"] is None: # This is null for users not on any team return False - for team in user["teams"]: - if team["name"] == team_name: - return True - return False + return any(team["name"] == team_name for team in user["teams"]) def label_mirror_dummy_users( diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py index d5c21c9fd1..aa268690ce 100644 --- a/zerver/lib/markdown/__init__.py +++ b/zerver/lib/markdown/__init__.py @@ -768,10 +768,7 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor): if parsed_url.netloc == "pasteboard.co": return False - for ext in IMAGE_EXTENSIONS: - if parsed_url.path.lower().endswith(ext): - return True - return False + return any(parsed_url.path.lower().endswith(ext) for ext in IMAGE_EXTENSIONS) def corrected_image_source(self, url: str) -> Optional[str]: # This function adjusts any URLs from linx.li and diff --git a/zerver/lib/narrow.py b/zerver/lib/narrow.py index 41077bd116..64144538dd 100644 --- a/zerver/lib/narrow.py +++ b/zerver/lib/narrow.py @@ -121,17 +121,14 @@ def is_web_public_narrow(narrow: Optional[Iterable[Dict[str, Any]]]) -> bool: if narrow is None: return False - for term in narrow: + return any( # Web-public queries are only allowed for limited types of narrows. # term == {'operator': 'streams', 'operand': 'web-public', 'negated': False} - if ( - term["operator"] == "streams" - and term["operand"] == "web-public" - and term["negated"] is False - ): - return True - - return False + term["operator"] == "streams" + and term["operand"] == "web-public" + and term["negated"] is False + for term in narrow + ) def build_narrow_filter(narrow: Collection[Sequence[str]]) -> Callable[[Mapping[str, Any]], bool]: