Skip to content

Problem with mypy 0.950 #960

Closed
Closed
@Savlik

Description

@Savlik

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions