piccolo
piccolo copied to clipboard
Provide better type hinting for Table instance creation
Currently piccolo.table.Table provides the __init__ method with **kwargs, which is not ideal for type hinting. Maybe we can use dataclass_transform decorator to deal with this.
For example:
from typing import dataclass_transform
from piccolo.columns import Varchar
from piccolo.table import Table
@dataclass_transform()
class BetterTable(Table): ...
class Schema(Table):
a = Varchar(length=255)
class BetterSchema(BetterTable):
a: Varchar = Varchar(length=255)
a = Schema(a=1)
b = BetterSchema(a=1)
Yes, this would be nice to have. I haven't played around much with dataclass_transform - I'll have a look, thanks!