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

Problem with mypy 0.950 #960

Closed
Savlik opened this issue May 11, 2022 · 3 comments
Closed

Problem with mypy 0.950 #960

Savlik opened this issue May 11, 2022 · 3 comments

Comments

@Savlik
Copy link

Savlik commented May 11, 2022

Hi,
I have the following code, that started failing type checks for mypy 0.950. From the error I assume, it is probably more an issue of attrs than mypy itself. Feel free to correct me. Also, if I change @attr.s() to @dataclass it works just fine. I have found one change in mypy 0.950 that can be related to this: python/mypy#12656
Thanks for any help

Code:

from typing import Generic, TypeVar
import attr

T = TypeVar("T")

@attr.s()
class Inner(Generic[T]):
    data: T = attr.ib()

@attr.s()
class Outer(Generic[T]):
    inner: Inner[T] = attr.ib()

@attr.s()
class SpecificOuter(Outer[T]):
    pass

def test() -> None:
    inner = Inner[int](data=0)

    Outer[int](inner=inner)  # OK
    SpecificOuter[int](inner=inner)  # Not OK

Error:

Argument "inner" to "SpecificOuter" has incompatible type "Inner[int]"; expected "Inner[T]" mypy(error)

Versions:
mypy: 0.950
attrs: 21.4.0
python: 3.8.10
OS: Ubuntu 20.04

@hynek
Copy link
Member

hynek commented May 12, 2022

From the error I assume, it is probably more an issue of attrs than mypy itself.

I'm not sure why you would think that. Almost all of relevant type logic lives in Mypy's attrs pluging. Looks like they broke subclassing of Generic[T] and only fixed it for dataclasses. :(

@Savlik
Copy link
Author

Savlik commented May 12, 2022

Yes, you are right. I was not sure. Thank you, I will close this issue.

@Savlik Savlik closed this as completed May 12, 2022
@hynek
Copy link
Member

hynek commented May 12, 2022

You could’ve kept it open to prevent more bug reports, but it looks like Jukka it already working on a fix so hopefully this will be a non-issue real soon. 🤞

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

2 participants