From d8561d9b7d37ef988b54a14aa2758354a80b1a41 Mon Sep 17 00:00:00 2001 From: golyalpha Date: Wed, 7 Jun 2023 16:41:18 +0200 Subject: [PATCH] Fix type annotations for models Classmethods `get` type annotations declared their return type as the various base model classes. This broke code hints and linters as a result, because they were incorrectly told Model.get returned `HashModel` (or whichever base model was in use) rather than `Model`. --- aredis_om/model/model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aredis_om/model/model.py b/aredis_om/model/model.py index 73bbf2a2..03e4feaf 100644 --- a/aredis_om/model/model.py +++ b/aredis_om/model/model.py @@ -1160,7 +1160,7 @@ async def delete( return await cls._delete(db, cls.make_primary_key(pk)) @classmethod - async def get(cls, pk: Any) -> "RedisModel": + async def get(cls:type[_T], pk: Any) -> _T: raise NotImplementedError async def update(self, **field_values): @@ -1368,7 +1368,7 @@ async def all_pks(cls): # type: ignore ) @classmethod - async def get(cls, pk: Any) -> "HashModel": + async def get(cls:type[_T], pk: Any) -> _T: document = await cls.db().hgetall(cls.make_primary_key(pk)) if not document: raise NotFoundError @@ -1559,7 +1559,7 @@ async def update(self, **field_values): await self.save() @classmethod - async def get(cls, pk: Any) -> "JsonModel": + async def get(cls:type[_T], pk: Any) -> _T: document = json.dumps(await cls.db().json().get(cls.make_key(pk))) if document == "null": raise NotFoundError