Is it possible to create distinct instances of dataclass?
from dataclasses import dataclass
from datetime import datetime
from time import sleep
class A:
def __init__(self):
self.time = datetime.now()
a1 = A().time
sleep(1)
a2 = A().time
assert a1 != a2
The above works fine. Let's now try the same with dataclass.
@dataclass
class B:
time = datetime.now()
b1 = B().time
sleep(1)
b2 = B().time
assert b1 != b2 # does not work
The benefit is avoiding sugary self but is it at the cost of creating class specific attributes instead of instance attributes via init?
Maybe dataclass should be used only when one instance is possible?