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

Type check error with asdict (2) #1150

Closed
dnlfm opened this issue Jun 15, 2023 · 4 comments
Closed

Type check error with asdict (2) #1150

dnlfm opened this issue Jun 15, 2023 · 4 comments

Comments

@dnlfm
Copy link

dnlfm commented Jun 15, 2023

Running MyPy for the following code:

from typing import Any
import attr

@attr.s(auto_attribs=True, kw_only=True, slots=True)
class MyClass:
    x: int

def my_serializer(record: Any, k: attr.Attribute, v: Any) -> Any:
    return v

m = MyClass(x=1)
k = attr.asdict(m, value_serializer=my_serializer)
print(k)

generates the error:

error: Argument 1 to "asdict" has incompatible type "MyClass"; expected "AttrsInstance"

Related to: #987

Versions:

  • attrs==23.1.0
  • mypy==0.812
@Tinche
Copy link
Member

Tinche commented Jun 15, 2023

Can you try Mypy 1.3.0?

@dnlfm
Copy link
Author

dnlfm commented Jun 15, 2023

@Tinche With MyPy 1.3.0 it works. Is it necessary to update MyPy to work with newer versions of attrs?

@Tinche
Copy link
Member

Tinche commented Jun 15, 2023

Yes, both the attrs plugin and Mypy itself is developing very rapidly, so I always recommend using the latest version if you can.

@dnlfm
Copy link
Author

dnlfm commented Jun 15, 2023

Unfortunately updating MyPy to 1.3.0 introduces other issues... I think I'll just skip it for now. Thank you anyway!

@hynek hynek closed this as completed Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants