Fix the type of the __dataclass_fields__ field on the Dataclass protocol.
Make the Protocol typing-only (remove the possibility of using isinstance and issubclass). The reason for this is that there was no way to differentiate between a dataclass type, and a dataclass instance:
@runtime_checkable
class Dataclass(Protocol):
__dataclass_fields__: ClassVar[dict[str, Field]]
@dataclass
class Bob:
a: int = 123
assert isinstance(Bob(), Dataclass) # fine
assert not isinstance(Bob, Dataclass) # This shouldn't be True, but it is!
That's because it can't tell that `__dataclass_fields__` is an *instance* attribute on the class, and not a class variable!
Therefore I removed the `runtime_checkable` wrapper.
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
__dataclass_fields__
field on theDataclass
protocol.isinstance
andissubclass
). The reason for this is that there was no way to differentiate between a dataclass type, and a dataclass instance:@dataclass class Bob: a: int = 123
assert isinstance(Bob(), Dataclass) # fine assert not isinstance(Bob, Dataclass) # This shouldn't be True, but it is!