Skip to content

Commit

Permalink
Improve Doc.get return value type (#80)
Browse files Browse the repository at this point in the history
* Improve Doc.get return value type

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
davidbrochart and pre-commit-ci[bot] authored Feb 15, 2024
1 parent e280c4e commit fb6caf2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions python/pycrdt/_doc.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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
from ._pycrdt import SubdocsEvent, TransactionEvent
from ._pycrdt import Transaction as _Transaction
from ._transaction import ReadTransaction, Transaction

T_BaseType = TypeVar("T_BaseType", bound=BaseType)


class Doc(BaseDoc):
def __init__(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fb6caf2

Please sign in to comment.