Message 381399 - Python tracker
Another counter-intuitive behaviour is the different behaviour of dataclasses depending on whether they were defined with the decorator or the make_dataclass factory method:
from __future__ import annotations
import dataclasses
mytype = int
@dataclasses.dataclass
class MyClass1:
foo: mytype = 1
MyClass2 = dataclasses.make_dataclass(
f'MyClass2',
[('foo', mytype, 1)]
)
print(dataclasses.fields(MyClass1)[0].type)
print(dataclasses.fields(MyClass2)[0].type)
Results in:
mytype
<class 'int'>