From 06d72e66856e7848eb4f5482b70f24e8393e3667 Mon Sep 17 00:00:00 2001 From: davfsa Date: Mon, 25 Jan 2021 11:57:40 +0100 Subject: [PATCH] Bump mypy to 0.800 and fix issues (#451) --- dev-requirements.txt | 2 +- hikari/config.py | 4 ++-- hikari/impl/cache.py | 6 +++--- hikari/impl/entity_factory.py | 4 ++-- hikari/impl/rest.py | 6 ++---- hikari/internal/cache.py | 6 +----- 6 files changed, 11 insertions(+), 17 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index a43cea6900..e8fba8a817 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -28,7 +28,7 @@ sphobjinv==2.0.1 # TYPE CHECKING # ################# -mypy==0.790 +mypy==0.800 ####################### # DEPENDENCY CHECKING # diff --git a/hikari/config.py b/hikari/config.py index 62a5e04505..f555e05d74 100644 --- a/hikari/config.py +++ b/hikari/config.py @@ -254,7 +254,7 @@ class HTTPTimeoutSettings: def _(self, attrib: attr.Attribute[typing.Optional[float]], value: typing.Optional[float]) -> None: # This error won't occur until some time in the future where it will be annoying to # try and determine the root cause, so validate it NOW. - if value is not None and (not isinstance(value, (float, int)) or value <= 0): # type: ignore[unreachable] + if value is not None and (not isinstance(value, (float, int)) or value <= 0): raise ValueError(f"HTTPTimeoutSettings.{attrib.name} must be None, or a POSITIVE float/int") @@ -325,7 +325,7 @@ class HTTPSettings: def _(self, _: attr.Attribute[typing.Optional[int]], value: typing.Optional[int]) -> None: # This error won't occur until some time in the future where it will be annoying to # try and determine the root cause, so validate it NOW. - if value is not None and (not isinstance(value, int) or value <= 0): # type: ignore[unreachable] + if value is not None and (not isinstance(value, int) or value <= 0): raise ValueError("http_settings.max_redirects must be None or a POSITIVE integer") _ssl: typing.Union[bool, ssl_.SSLContext] = attr.ib( diff --git a/hikari/impl/cache.py b/hikari/impl/cache.py index 941c4e1ac8..03ff0adfec 100644 --- a/hikari/impl/cache.py +++ b/hikari/impl/cache.py @@ -1411,10 +1411,10 @@ def _garbage_collect_message( if guild_record: self._garbage_collect_member(guild_record, message.object.member, decrement=1) - if message.object.referenced_message and message.object.referenced_message is not undefined.UNDEFINED: + if message.object.referenced_message: self._garbage_collect_message(message.object.referenced_message, decrement=1) - if message.object.mentions.users and message.object.mentions.users is not undefined.UNDEFINED: + if message.object.mentions.users: for user in message.object.mentions.users.values(): self._garbage_collect_user(user, decrement=1) @@ -1489,7 +1489,7 @@ def _set_message( mention_users = {user_id: self._set_user(user) for user_id, user in message.mentions.users.items()} referenced_message: typing.Optional[cache_utility.RefCell[cache_utility.MessageData]] = None - if message.referenced_message and message.referenced_message is not undefined.UNDEFINED: + if message.referenced_message: referenced_message = self._set_message(message.referenced_message) if message.id not in self._referenced_messages and message.id not in self._message_entries: diff --git a/hikari/impl/entity_factory.py b/hikari/impl/entity_factory.py index 797c308601..e2375756e6 100644 --- a/hikari/impl/entity_factory.py +++ b/hikari/impl/entity_factory.py @@ -879,8 +879,8 @@ def serialize_embed( # noqa: C901 # of debugging. The case that there are `None` should be detected immediately by # static type checkers, regardless. - name = str(field.name) if field.name is not None else None # type: ignore[unreachable] - value = str(field.value) if field.value is not None else None # type: ignore[unreachable] + name = str(field.name) if field.name is not None else None + value = str(field.value) if field.value is not None else None if name is None: raise TypeError(f"in embed.fields[{i}].name - cannot have `None`") diff --git a/hikari/impl/rest.py b/hikari/impl/rest.py index f1a22ba50f..c8c78c2616 100644 --- a/hikari/impl/rest.py +++ b/hikari/impl/rest.py @@ -1012,9 +1012,8 @@ async def create_message( embed = content content = undefined.UNDEFINED - # os.PathLike is missing @runtime_checkable causing mypy to complain elif undefined.count(attachment, attachments) == 2 and isinstance( - content, (files.Resource, files.RAWISH_TYPES, os.PathLike) # type: ignore[misc] + content, (files.Resource, files.RAWISH_TYPES, os.PathLike) ): # Syntatic sugar, common mistake to accidentally send an attachment # as the content, so lets detect this and fix it for the user. This @@ -1414,9 +1413,8 @@ async def execute_webhook( embed = content content = undefined.UNDEFINED - # os.PathLike is missing @runtime_checkable causing mypy to complain elif undefined.count(attachment, attachments) == 2 and isinstance( - content, (files.Resource, files.RAWISH_TYPES, os.PathLike) # type: ignore[misc] + content, (files.Resource, files.RAWISH_TYPES, os.PathLike) ): # Syntatic sugar, common mistake to accidentally send an attachment # as the content, so lets detect this and fix it for the user. This diff --git a/hikari/internal/cache.py b/hikari/internal/cache.py index ee8c8d5ab7..8e8b91110a 100644 --- a/hikari/internal/cache.py +++ b/hikari/internal/cache.py @@ -754,11 +754,7 @@ def build_from_entity( if not member and message.member: member = RefCell(MemberData.build_from_entity(message.member)) - if ( - not referenced_message - and message.referenced_message - and message.referenced_message is not undefined.UNDEFINED - ): + if not referenced_message and message.referenced_message: referenced_message = RefCell(MessageData.build_from_entity(message.referenced_message)) return cls(