tortoise/tortoise-orm

Missing type tags when using async for ... in ... in PyCharm

panla opened this issue · 3 comments

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

Failed to reproduce in PyCharm 2023.1.3 (Community Edition) with tortoise-orm==0.21.5
image

@panla I believe that is a BUG of PyCharm!

Currently, you have two ways to improve prompt:

  1. Use for (await queryset) instead of async for
for instance in (await User.filter()):
    print(instance.id)
  1. Add overload to source code of tortoise/queryset.py
    @overload
    def __getitem__(self, key: int) -> "MODEL": ...
image