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

DJAS002: Set fields as not required, proper type annotations #12

Closed
4 tasks done
Viicos opened this issue Dec 21, 2023 · 1 comment · Fixed by #46
Closed
4 tasks done

DJAS002: Set fields as not required, proper type annotations #12

Viicos opened this issue Dec 21, 2023 · 1 comment · Fixed by #46
Labels
dynamic-stubs Issue related to dynamic stub generation

Comments

@Viicos
Copy link
Owner

Viicos commented Dec 21, 2023

Follow up on #10:

  • Set fields as NotRequired: is there a reliable way of determining this? Field.get_default() seems to always return a value even though a field value should be provided. Django seems to try inserting the value, so it might not be possible to know in advance? Should we apply some common sense and set fields as being not required if there's a default/db_default or null=True? see this discussion. Implemented, but should also look at the mypy plugin:
  • Add the ability to set some fields as being required in create signatures #15
  • Regarding type annotations, this will depend on how things will change in django-stubs, see this discussion.
  • Special case generic foreign keys
  • What to do on inheritance? Proxy models?
@Viicos
Copy link
Owner Author

Viicos commented Feb 2, 2024

It seems that different logic is involved between __init__ and create, so:

  • Create to separated rules for them. Use an abstract common base transformer class that annotates the self argument, and each subclass should provide the self annotation (i.e. self: BaseManager[model_name]/_QuerySet[model_name, _Row]/model_name)
  • For models __init__, look a the actual runtim implementation, there is a lot going on. In the future, also support property setters

Edit: actually logic doesn't differ that much. This is still refactored as described so that separated rules can be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dynamic-stubs Issue related to dynamic stub generation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant