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]: