ponyorm / pony

Pony Object Relational Mapper
Apache License 2.0
3.58k stars 242 forks source link

Excepted type error warning in PyCharm #674

Closed JoshYuJump closed 1 year ago

JoshYuJump commented 1 year ago

My code is:

product = select(p for p in Product if p.id = 1)

In PyCharm IDE it show the error tip in Product position:

Expected type 'collections.Iterable', got 'Type[Product]' instead 
JoshYuJump commented 1 year ago

It's related to type hints. So I tried pony-stubs, the warning has not gone away.

My finally solution is add .pyi to my existing BaseMixin.

# db.py
class BaseMixin:
    ...

# db.pyi
class BaseMixin(metaclass=EntityMeta): ...

# models.py
class Product(BaseMixin, db.Entity):
    id = PrimaryKey(auto=True)

Then, the warning gone.