improve strict typing

This commit is contained in:
ducklet 2023-03-28 23:32:24 +02:00
parent 8b5cbdf903
commit 2963a1d3f6
2 changed files with 25 additions and 16 deletions

View file

@ -11,6 +11,7 @@ from typing import (
Container,
Literal,
Mapping,
Protocol,
Type,
TypedDict,
TypeVar,
@ -29,6 +30,11 @@ JSONObject = dict[str, JSON]
T = TypeVar("T")
class Model(Protocol):
__table__: ClassVar[Table]
mapper_registry = registry()
metadata = mapper_registry.metadata
@ -207,7 +213,7 @@ def utcnow():
@mapper_registry.mapped
@dataclass
class DbPatch:
__table__ = Table(
__table__: ClassVar[Table] = Table(
"db_patches",
metadata,
Column("id", Integer, primary_key=True),
@ -224,7 +230,7 @@ db_patches = DbPatch.__table__
@mapper_registry.mapped
@dataclass
class Progress:
__table__ = Table(
__table__: ClassVar[Table] = Table(
"progress",
metadata,
Column("id", String, primary_key=True), # ULID
@ -274,7 +280,7 @@ class Progress:
@mapper_registry.mapped
@dataclass
class Movie:
__table__ = Table(
__table__: ClassVar[Table] = Table(
"movies",
metadata,
Column("id", String, primary_key=True), # ULID
@ -352,7 +358,7 @@ Relation = Annotated[T | None, _RelationSentinel]
@mapper_registry.mapped
@dataclass
class Rating:
__table__ = Table(
__table__: ClassVar[Table] = Table(
"ratings",
metadata,
Column("id", String, primary_key=True), # ULID
@ -409,7 +415,7 @@ class UserGroup(TypedDict):
@mapper_registry.mapped
@dataclass
class User:
__table__ = Table(
__table__: ClassVar[Table] = Table(
"users",
metadata,
Column("id", String, primary_key=True), # ULID
@ -449,7 +455,7 @@ class GroupUser(TypedDict):
@mapper_registry.mapped
@dataclass
class Group:
__table__ = Table(
__table__: ClassVar[Table] = Table(
"groups",
metadata,
Column("id", String, primary_key=True), # ULID