piccolo icon indicating copy to clipboard operation
piccolo copied to clipboard

Provide better type hinting for Table instance creation

Open observerw opened this issue 6 months ago • 1 comments

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)
Image

observerw avatar Jun 11 '25 11:06 observerw

Yes, this would be nice to have. I haven't played around much with dataclass_transform - I'll have a look, thanks!

dantownsend avatar Jun 11 '25 21:06 dantownsend