Skip to content

Commit

Permalink
Bump mypy from 1.5.1 to 1.6.1 (#1733)
Browse files Browse the repository at this point in the history
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: davfsa <[email protected]>
  • Loading branch information
dependabot[bot] and davfsa authored Oct 28, 2023
1 parent ffc8f11 commit 9583914
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
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

0 comments on commit 9583914

Please sign in to comment.