Skip to content

False error for dataclass slots when class is referenced earlier #11827

@wrobell

Description

@wrobell

Please consider

import dataclasses as dtc
import asyncio

PublishedMessagesVar = dict[int, 'PublishedMessages']

@dtc.dataclass(frozen=True, slots=True)
class PublishedMessages:
    task: asyncio.Future[int]
    left: int
    right: int

then

$ mypy t2.py
t2.py:7: error: "PublishedMessages" both defines "__slots__" and is used with "slots=True"
Found 1 error in 1 file (checked 1 source file)

Above with Mypy 0.930, Python 3.10.1

There is no problem

  • when line with PublishedMessagesVar is removed
  • with Mypy 0.921

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions