3 ms·
Off the top of my head, python classes which shouldn't/can't be dataclasses: The entire modules typing, os, sys, struct, inspect, json. Anything which is a me
by kortex 4y ago
Off the top of my head, python classes which shouldn't/can't be dataclasses:
The entire modules typing, os, sys, struct, inspect, json.
Anything which is a metaclass or relies on metaclass behavior (you have to be careful combining dataclass with other metaclasses, it's possible but with footguns akimbo).
Datetime actually should be a dataclass, but that api is so crufty and unintuitive that it's never gonna happen, and trying to shoehorn it to a dataclass would break oodles of libraries and applications.
threading: Thread, Lock, Rlock anything whichs uses locks
Numpy.ndarry, pandas.Series, pandas.Dataframe, torch.Tensor. Numerous scikit-learn models.
Probably the vast majority of c extensions.
pydantic.BaseModel, fastapi.FastAPI, fastapi.APIRouter (same with flask/django), celery.Task.
I could go on but I think I've made my point. There are plenty of non-dataclass use cases out there.