Missing type tags when using async for ... in ... in PyCharm
panla opened this issue · 3 comments
panla commented
Describe the bug
A clear and concise description of what the bug is.
when use async for instance in Model.filter(), there no type info.
async for team in event.participants:
print(team.id)
The team.id in this code does not prompt for the id attribute,
Unresolved attribute reference 'id' for class 'QuerySet'
in version 0.19.3
def filter(cls: Type[MODEL], *args: Q, **kwargs: Any) -> QuerySet[MODEL]:
in version 0.21.5
def filter(cls, *args: Q, **kwargs: Any) -> QuerySet[Self]:
To Reproduce
Steps to reproduce the behavior, preferably a small code snippet.
Expected behavior
A clear and concise description of what you expected to happen.
Additional context
Add any other context about the problem here.
version: 0.21.5
close
if is is not a bug, please close it
waketzheng commented
panla commented
waketzheng commented
@panla I believe that is a BUG of PyCharm!
Currently, you have two ways to improve prompt:
- Use
for (await queryset)
instead ofasync for
for instance in (await User.filter()):
print(instance.id)
- Add overload to source code of tortoise/queryset.py
@overload
def __getitem__(self, key: int) -> "MODEL": ...