Verified Commit de015c10 authored by Jakob Moser's avatar Jakob Moser
Browse files

Annotate primary key type in Base and Card

parent bd46f183
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
from __future__ import annotations

from typing import cast
from uuid import UUID, uuid4

from sqlalchemy.orm import Mapped, mapped_column
@@ -9,7 +10,7 @@ from poolpay.model.Retrievable import Retrievable
from poolpay.model.Uuid import Uuid


class Base(Retrievable):
class Base(Retrievable[UUID]):
    """
    A type with a UUID, stored in the database.

@@ -22,7 +23,7 @@ class Base(Retrievable):
    uuid: Mapped[UUID] = mapped_column(Uuid(), primary_key=True, default=uuid4)

    @classmethod
    def get_only[T](cls: type[T], uuid: str | UUID) -> T | None:
    def get_only[T: Base](cls: type[T], uuid: str | UUID) -> T | None:
        if isinstance(uuid, str):
            try:
                # Manually convert the uuid to a UUID object (even though sqlalchemy-uuid would do that
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ from poolpay.model.Person import Person
from poolpay.model.Retrievable import Retrievable


class Card(Retrievable):
class Card(Retrievable[int]):
    """
    A card, most likely a pool card. It has an id (which is read from the card), and belongs to a person.
    """