Skip to content

Commit

Permalink
Bump mypy to 0.800 and fix issues (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
davfsa authored Jan 25, 2021
1 parent a1bd5a0 commit 06d72e6
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sphobjinv==2.0.1
# TYPE CHECKING #
#################

mypy==0.790
mypy==0.800

#######################
# DEPENDENCY CHECKING #
Expand Down
4 changes: 2 additions & 2 deletions hikari/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions hikari/impl/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions hikari/impl/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`")
Expand Down
6 changes: 2 additions & 4 deletions hikari/impl/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions hikari/internal/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 06d72e6

Please sign in to comment.