mongoengine icon indicating copy to clipboard operation
mongoengine copied to clipboard

Improve typing hint of attributes

Open JustAnotherVeryNormalDeveloper opened this issue 11 months ago • 0 comments

When working on Visual Studio Code, the hint of the type isn't very helpful. Could we make it better ? can I help doing that ?

Example:

from mongoengine import Document, StringField


class User(Document):  
    name = StringField(required=True)
    surname = StringField(required=False)


user = User(name="John", surname="Wick")  

user.name
user.surname

The proposition of Visual Studio Code type are: (variable) name: StringField | Unknown (variable) surname: StringField | Unknown

Yet, the print give a really practical type:

  • print(type(user.name)) -> <class 'str'>

I want make my code more robust and be able to see that on the values: (variable) name: str (variable) surname: str | None

The information that it can, or not, be None, can help a lot.