Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "model:docstring" command to generate type hinting for models #705

Closed
girardinsamuel opened this issue Jun 2, 2022 · 2 comments · Fixed by #706
Closed

Add a "model:docstring" command to generate type hinting for models #705

girardinsamuel opened this issue Jun 2, 2022 · 2 comments · Fixed by #706
Labels
feature request A feature that does not yet exist but will be a good addition to the library

Comments

@girardinsamuel
Copy link
Contributor

To have type hinting for model attributes what we can do is to add a new command model:docstring to generate automatically type hints for the models. Then we would just have to copy/paste generated hints in our model classes.

This command existed before so we just have to write it back here. IMO it should live in the ORM codebase so that non Masonite users can benefit of it.

Originally posted by @girardinsamuel in #695 (comment)

@girardinsamuel
Copy link
Contributor Author

It's linked to the issue #240 but not an exact duplicate. Indeed it would be great to generate a model docstring but here we need to generate the model type hints too.
So maybe generating two parts is the solution:

Model Docstring:
"""Model Definition (generated with love by Masonite)
    id: integer default: None
    name: string(255) default: None
    email: string(255) default: None
    password: string(255) default: None
    remember_token: string(255) default: None
    created_at: datetime(6) default: CURRENT_TIMESTAMP(6)
    updated_at: datetime(6) default: CURRENT_TIMESTAMP(6)
    customer_id: string(255) default: None
    plan_id: string(255) default: None
    is_active: integer default: None
    verified_at: datetime default: None
"""

Type Hints:
from pendulum.datetime import DateTime
id: int
name: str
email: str
password: str
remember_token: str
created_at: "DateTime"
updated_at: "DateTime"
customer_id: str
plan_id: str
is_active: int
verified_at: "DateTime"

⚠️ dates/datetimes can be tricky. If declared in casts parameters will be DateTime instances else it will be str instances.

@josephmancuso
Copy link
Member

FYI This should also solve #240

@josephmancuso josephmancuso added the feature request A feature that does not yet exist but will be a good addition to the library label Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature that does not yet exist but will be a good addition to the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants