泛型类型

from typing import TypeVarGeneric
T = TypeVar('T')


class Size(Generic[T]):
    def __init__(self, width: T, height: T):
        self.width = width
        self.height = height

    def as_text(self):
        return f"[{self.width}{self.height}]"


size_int = Size[int](58)
text_int = size_int.as_text()
# text_int is "[5; 8]"

size_float = Size[float](3.71.58)
text_float = size_float.as_text()
# textFloat is "[3.7; 1.58]"

print(f"{text_int=}")
print(f"{text_float=}")