MongoEngine / MongoEngine/mongoengine
Improve typing hint of attributes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the User example in Visual Studio Code and inspect how the StringField attributes are currently inferred. Define and verify the expected hints: str for required fields and str | None for optional fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100