[Django] #36212: How about providing type safe access to form field data?

9 views
Skip to first unread message

Django

unread,
Feb 24, 2025, 1:09:08 AM2/24/25
to django-...@googlegroups.com
#36212: How about providing type safe access to form field data?
------------------------------+-----------------------------------------
Reporter: Justin Black | Type: Uncategorized
Status: new | Component: Uncategorized
Version: 5.1 | Severity: Normal
Keywords: form, field | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+-----------------------------------------
Right now only cleaned data is acessed in a dict in python.
This means that type hcecking code does not know the type of that dict
unless it is described as a typeddict.
How about providing type safe access to form field data?

```
class FormOptions(forms.Form):
prompt = forms.CharField(widget=forms.Textarea)
n = forms.IntegerField(min_value=1, max_value=10, initial=1)

form_options = FormOptions({'prompt': 'a', 'n': 2})
```

one could access it as:
form_options.prompt.cleaned_data
or
form_options.prompt

This would allow code to access type safe values for a form in python.
--
Ticket URL: <https://code.djangoproject.com/ticket/36212>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 24, 2025, 1:09:51 AM2/24/25
to django-...@googlegroups.com
#36212: How about providing type safe access to form field data?
-------------------------------+--------------------------------------
Reporter: Justin Black | Owner: (none)
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 5.1
Severity: Normal | Resolution:
Keywords: form, field | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Justin Black:

Old description:

> Right now only cleaned data is acessed in a dict in python.
> This means that type hcecking code does not know the type of that dict
> unless it is described as a typeddict.
> How about providing type safe access to form field data?
>
> ```
> class FormOptions(forms.Form):
> prompt = forms.CharField(widget=forms.Textarea)
> n = forms.IntegerField(min_value=1, max_value=10, initial=1)
>
> form_options = FormOptions({'prompt': 'a', 'n': 2})
> ```
>
> one could access it as:
> form_options.prompt.cleaned_data
> or
> form_options.prompt
>
> This would allow code to access type safe values for a form in python.

New description:

Right now only cleaned data is acessed in a dict in python.
This means that type hcecking code does not know the type of that dict
unless it is described as a typeddict.
How about providing type safe access to form field data?


{{{
class FormOptions(forms.Form):
prompt = forms.CharField(widget=forms.Textarea)
n = forms.IntegerField(min_value=1, max_value=10, initial=1)

form_options = FormOptions({'prompt': 'a', 'n': 2})
}}}

one could access it as:
form_options.prompt.cleaned_data
or
form_options.prompt

This would allow code to access type safe values for a form in python.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36212#comment:1>

Django

unread,
Feb 24, 2025, 3:37:50 AM2/24/25
to django-...@googlegroups.com
#36212: How about providing type safe access to form field data?
------------------------------+--------------------------------------
Reporter: Justin Black | Owner: (none)
Type: New feature | Status: closed
Component: Forms | Version: 5.1
Severity: Normal | Resolution: wontfix
Keywords: form, field | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by Sarah Boyce):

* component: Uncategorized => Forms
* resolution: => wontfix
* status: new => closed
* type: Uncategorized => New feature

Comment:

As this is requesting a new feature for Django. The recommended path
forward is to first propose and discuss the idea with the community and
gain consensus. To do that, please consider starting a new conversation on
the [https://forum.djangoproject.com/c/internals/5 Django Forum], where
you'll reach a broader audience and receive additional feedback.

I'll close the ticket for now, but if the community agrees with the
proposal, please return to this ticket and reference the forum discussion
so we can re-open it. For more information, please refer to
[https://docs.djangoproject.com/en/stable/internals/contributing/bugs-and-
features/#requesting-features the documented guidelines for requesting
features].

I also recommend you look for similar type conversations and try to
incorporate or summarize opinions from these.
--
Ticket URL: <https://code.djangoproject.com/ticket/36212#comment:2>
Reply all
Reply to author
Forward
0 new messages