Skip to content

Improve typing hint of attributes #2868

Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions