Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

ruff: Fix SIM110 Use `return any(…)` instead of `for` loop.

Anders Kaseorgb8b29dc3ad57
diff --git a/zerver/data_import/mattermost.py b/zerver/data_import/mattermost.py
index 53e4fc463d1..e2f20308286 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 d5c21c9fd12..aa268690ce7 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 41077bd1166..64144538dd5 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]: