#34445 closed Bug (fixed)
DateField.input_formats cannot be printed
| Reported by: | stefan6419846 | Owned by: | David Sanders |
|---|---|---|---|
| Component: | Utilities | Version: | 3.2 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I am trying to display the input formats for django.forms.fields.DateField. This seems to fail at the moment when using __str__, while __repr__ works.
Example code:
from django.forms.fields import DateField print(repr(DateField().input_formats)) print(DateField().input_formats)
This will result in the following error:
Traceback (most recent call last): File "<console>", line 1, in <module> TypeError: __str__ returned non-string (type list)
I would have expected the string representation to be available as well instead of failing with an internal Python error.
Change History (6)
comment:2 by , 3 years ago
| Component: | Uncategorized → Utilities |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Bug |
comment:3 by , 3 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:4 by , 3 years ago
| Has patch: | set |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
Note:
See TracTickets
for help on using tickets.
Hi, thanks for the report!
Interesting:
> lazy_val = lazy(get_format, str, list, tuple)("DATE_INPUT_FORMATS") > lazy_val.__str__() ['%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', '%b %d %Y', '%b %d, %Y', '%d %b %Y', '%d %b, %Y', '%B %d %Y', '%B %d, %Y', '%d %B %Y', '%d %B, %Y'] > str(lazy_val) *** TypeError: __str__ returned non-string (type list) > type(lazy_val.__str__()) <class 'list'>Confirmed
__str__()is returning alist.