Jonesus / pony-stubs

Python type stubs for Pony ORM
https://pypi.org/project/pony-stubs/
MIT License
9 stars 0 forks source link

Name "db.Entity" is not defined #9

Open eternal-sorrow opened 2 years ago

eternal-sorrow commented 2 years ago
from pony import orm

db = orm.Database()
db.bind(provider='sqlite', filename='db.sqlite')

class A(db.Entity):
    name = orm.Required(str, max_len=64, index=True)

mypy says: Name "db.Entity" is not defined

vahvero commented 1 year ago

Have you had a look into the README.md file examples?

# Using `db.Entity` directly won't work, as both MyPy and Pyright won't
# allow inheriting a class from a variable. For Pyright this declaration
# is enough misdirection for it not to complain, but MyPy needs an extra
# `type: ignore` comment above each model declaration to work.
DbEntity = db.Entity

# <example declarations>
Xandaros commented 1 year ago

For Pyright, I don't think any changes are necessary anymore. Mine doesn't complain about directly using db.Entity.

mypy still does, though.