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

ModelChoiceField could use a type argument #698

Closed
mthuurne opened this issue Sep 3, 2021 · 1 comment · Fixed by #1889
Closed

ModelChoiceField could use a type argument #698

mthuurne opened this issue Sep 3, 2021 · 1 comment · Fixed by #1889
Labels
bug Something isn't working

Comments

@mthuurne
Copy link
Contributor

mthuurne commented Sep 3, 2021

Bug report

What's wrong

When subclassing django.forms.ModelChoiceField and overriding label_from_instance(), the type of the method argument is Model, but the implementation likely needs to know which concrete model type is being passed.

How is that should be

While it is possible to work around this using cast() or assert isinstance(), having a type argument for the model type (_M) on ModelChoiceField would be a more elegant solution.

System information

  • django version: 3.2.6
  • django-stubs version: 1.8.0
@mthuurne mthuurne added the bug Something isn't working label Sep 3, 2021
@sobolevn
Copy link
Member

sobolevn commented Sep 3, 2021

In this case we would need to update both django-stubs (types) and django-stubs-ext (runtime __class_getattr__).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants