ponyorm / pony

Pony Object Relational Mapper
Apache License 2.0
3.63k stars 245 forks source link

Auto-complete on entity construction when using intellisense (VSCode) #715

Open jat255 opened 4 months ago

jat255 commented 4 months ago

I'm brand new to using Pony, but wondering if what I'm expecting to see is possible...

Let's say I create a model/DB table:

class SchemaVersion(db.Entity):
    id = PrimaryKey(int, auto=True)
    version = Required(str, unique=True)
    version_date = Required(date, unique=True)

Later on in my code, I would create a new entity by writing something like sv = SchemaVersion(version='1.0.0', version_date=dt.date.today()). Given that I'm a forgetful programmer, I would hope that it would show me the class attributes when I try to create a new instance, but when I try this in VSCode, I see the following auto-completion:

image

Apart from reimplementing each class's __init__() method, is there a way to structure my code such that Intellisense can pick up the attribute definitions? I guess my question is: is this the intended behavior, or am I doing something incorrect with how I'm defining my models?

It appears to work if I define my model like this, but I'm not sure if this is compatible with how Pony does things (I think it should be, but I'm not sure):

class SchemaVersion(db.Entity):
    id = PrimaryKey(int, auto=True)
    version = Required(str, unique=True)
    version_date = Required(date, unique=True)

    def __init__(self, version: str, version_date: date, **kwargs):
        super().__init__(version=version, version_date=version_date, **kwargs)

image

This also requires writing a lot more boilerplate code for each class, unforunately.

dan-bowen commented 2 months ago

+1 for code completion in IDEs.