-
Notifications
You must be signed in to change notification settings - Fork 122
Open
Description
Summary
The get() classmethod on RedisModel, HashModel, and JsonModel returns a generic type that doesn't properly reflect the actual model subclass. This breaks IDE type inference and linter checks.
Current behavior
class User(HashModel):
name: str
user = await User.get("123")
# IDE thinks `user` is `Model`, not `User`
# user.name doesn't autocompleteExpected behavior
user = await User.get("123")
# IDE knows `user` is `User`
# user.name autocompletes correctlyTechnical details
Current signature:
async def get(cls: Type["Model"], pk: Any) -> "Model"Should use proper TypeVar binding so the return type matches the calling class:
async def get(cls: Type[_T], pk: Any) -> _TThis pattern should be applied consistently to:
RedisModel.get()HashModel.get()JsonModel.get()- Any other classmethods that return model instances (e.g.,
save()returningself)
Prior work
PR #520 attempted this fix but was closed due to staleness. The approach was correct but needs to be updated for the current codebase.
Metadata
Metadata
Assignees
Labels
No labels