Skip to content

Provide better type hinting for Table instance creation #1210

@observerw

Description

@observerw

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions