From c944adfcc682abc6c30be4fd694d2202a5fbb702 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 31 May 2022 15:09:19 -0700 Subject: [PATCH] mypy: Enable redundant-expr errors. Signed-off-by: Anders Kaseorg --- pyproject.toml | 5 +++++ tools/lib/capitalization.py | 2 +- tools/lib/template_parser.py | 2 +- zerver/lib/mention.py | 3 +-- zerver/lib/scim.py | 2 +- zerver/lib/webhooks/common.py | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e3b92d0dc1..92b1b7e275 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,11 @@ disallow_untyped_calls = false disallow_untyped_decorators = false warn_return_any = false +# Enable optional errors. +enable_error_code = [ + "redundant-expr", +] + # Display the codes needed for # type: ignore[code] annotations. show_error_codes = true diff --git a/tools/lib/capitalization.py b/tools/lib/capitalization.py index 2510b5b2ec..4eee7407e9 100644 --- a/tools/lib/capitalization.py +++ b/tools/lib/capitalization.py @@ -218,7 +218,7 @@ def check_capitalization(strings: List[str]) -> Tuple[List[str], List[str], List capitalized = is_capitalized(safe_text) if not capitalized: errors.append(text) - elif capitalized and has_ignored_phrase: + elif has_ignored_phrase: ignored.append(text) banned_word_errors.extend(check_banned_words(text)) diff --git a/tools/lib/template_parser.py b/tools/lib/template_parser.py index a015e445fb..76655aa33b 100644 --- a/tools/lib/template_parser.py +++ b/tools/lib/template_parser.py @@ -464,7 +464,7 @@ def validate(fn: Optional[str] = None, text: Optional[str] = None) -> List[Token f"Tag must be self-closing: {tag} at {fn} line {token.line}, col {token.col}" ) elif kind == "html_singleton": - if not state.foreign and tag not in HTML_VOID_TAGS: + if tag not in HTML_VOID_TAGS: raise TemplateParserException( f"Tag must not be self-closing: {tag} at {fn} line {token.line}, col {token.col}" ) diff --git a/zerver/lib/mention.py b/zerver/lib/mention.py index 232946aa61..7a1bd3d1a1 100644 --- a/zerver/lib/mention.py +++ b/zerver/lib/mention.py @@ -87,8 +87,7 @@ class MentionBackend: # We expect callers who take advantage of our cache to supply both # id and full_name in the user mentions in their messages. for user in user_list: - if user.id is not None and user.full_name is not None: - self.user_cache[(user.id, user.full_name)] = user + self.user_cache[(user.id, user.full_name)] = user result += user_list diff --git a/zerver/lib/scim.py b/zerver/lib/scim.py index a3670b4f19..b21125565e 100644 --- a/zerver/lib/scim.py +++ b/zerver/lib/scim.py @@ -181,7 +181,7 @@ class ZulipSCIMUser(SCIMUser): self._full_name_new_value = new_value def change_is_active(self, new_value: bool) -> None: - if new_value is not None and new_value != self.obj.is_active: + if new_value != self.obj.is_active: self._is_active_new_value = new_value def handle_replace( diff --git a/zerver/lib/webhooks/common.py b/zerver/lib/webhooks/common.py index fe89839166..4e736c7a87 100644 --- a/zerver/lib/webhooks/common.py +++ b/zerver/lib/webhooks/common.py @@ -114,7 +114,7 @@ def check_send_webhook_message( # double escape their URLs in a manner that escaped space characters # (%20) are never properly decoded. We work around that by making sure # that the URL parameters are decoded on our end. - if stream is not None and unquote_url_parameters: + if unquote_url_parameters: stream = unquote(stream) if user_specified_topic is not None: