Closed
Description
from dataclasses import dataclass
from typing import Dict
from typing_extensions import Protocol
@dataclass
class A:
pass
class IsDataclass(Protocol):
__dataclass_fields__: Dict
def dataclass_only(x: IsDataclass):
pass
dataclass_only(A())
When running mypy on this code, I'd expect no warning, but I get
test.py:16: error: Argument 1 to "dataclass_only" has incompatible type "A"; expected "IsDataclass".
While checking for __dataclass_fields__
might not look like the best thing to go for, it's what dataclasses.is_dataclass
checks for as well, so this seems like the most reliable condition right now.
I'd assume it happens because the dataclass-wrapper adds this attribute, and mypy only checks the class definition itself. Can this be fixed?