Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump mypy from 1.5.1 to 1.6.1 #1733

Merged
merged 2 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev-requirements/mypy.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mypy==1.5.1
mypy==1.6.1
15 changes: 9 additions & 6 deletions hikari/internal/attrs_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

import attrs

ModelT = typing.TypeVar("ModelT")
ModelT = typing.TypeVar("ModelT", bound=attrs.AttrsInstance)
SKIP_DEEP_COPY: typing.Final[str] = "skip_deep_copy"

_DEEP_COPIERS: typing.MutableMapping[
Expand All @@ -60,15 +60,15 @@ def invalidate_deep_copy_cache() -> None:


def get_fields_definition(
cls: type,
cls: typing.Type[attrs.AttrsInstance],
) -> typing.Tuple[
typing.Sequence[typing.Tuple[attrs.Attribute[typing.Any], str]], typing.Sequence[attrs.Attribute[typing.Any]]
]:
"""Get a sequence of init key-words to their relative attribute.
Parameters
----------
cls : typing.Type[ModelT]
cls : typing.Type[attrs.AttrsInstance]
The attrs class to get the fields definition for.
Returns
Expand All @@ -79,7 +79,10 @@ def get_fields_definition(
init_results: typing.List[typing.Tuple[attrs.Attribute[typing.Any], str]] = []
non_init_results: typing.List[attrs.Attribute[typing.Any]] = []

for field in attrs.fields(cls):
# Mypy has a bug where it will always report
# "Argument 1 to "fields" has incompatible type "Type[AttrsInstance]"; expected an attrs class"
# even if the type is correct.
for field in attrs.fields(cls): # type: ignore[misc]
if field.init:
key_word = field.name[1:] if field.name.startswith("_") else field.name
init_results.append((field, key_word))
Expand Down Expand Up @@ -107,8 +110,8 @@ def generate_shallow_copier(cls: typing.Type[ModelT]) -> typing.Callable[[ModelT
from hikari.internal import ux

kwargs, setters = get_fields_definition(cls)
kwargs = ",".join(f"{kwarg}=m.{attrsibute.name}" for attrsibute, kwarg in kwargs)
setters = ";".join(f"r.{attrsibute.name}=m.{attrsibute.name}" for attrsibute in setters) + ";" if setters else ""
kwargs = ",".join(f"{kwarg}=m.{attribute.name}" for attribute, kwarg in kwargs)
setters = ";".join(f"r.{attribute.name}=m.{attribute.name}" for attribute in setters) + ";" if setters else ""
code = f"def copy(m):r=cls({kwargs});{setters}return r"
globals_ = {"cls": cls}
_LOGGER.log(ux.TRACE, "generating shallow copy function for %r: %r", cls, code)
Expand Down