diff --git a/python/pycrdt/_doc.py b/python/pycrdt/_doc.py index c56d0b1..66a92bf 100644 --- a/python/pycrdt/_doc.py +++ b/python/pycrdt/_doc.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Callable, Type, cast +from typing import Callable, Type, TypeVar, cast from ._base import BaseDoc, BaseType, base_types from ._pycrdt import Doc as _Doc @@ -8,6 +8,8 @@ from ._pycrdt import Transaction as _Transaction from ._transaction import ReadTransaction, Transaction +T_BaseType = TypeVar("T_BaseType", bound=BaseType) + class Doc(BaseDoc): def __init__( @@ -73,7 +75,7 @@ def __getitem__(self, key: str) -> BaseType: def __iter__(self): return iter(self.keys()) - def get(self, key: str, *, type: Type[BaseType]) -> BaseType: + def get(self, key: str, *, type: Type[T_BaseType]) -> T_BaseType: value = type() self[key] = value return value