#35750: Separate method for values_list(..., flat=True), deprecate that kwarg
-------------------------------------+-------------------------------------
Reporter: ivan-klass | Type:
| Cleanup/optimization
Status: new | Component: Database
| layer (models, ORM)
Version: 5.1 | Severity: Normal
Keywords: values_list flat | Triage Stage:
flag QuerySet ValuesQuerySet | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
The `flat=True` behavior changes the meaning and signature of the method
completely.
It's an obvious example of the
[https://martinfowler.com/bliki/FlagArgument.html "flag argument"]
antipattern (more [https://luzkan.github.io/smells/flag-argument python
examples])
especially because both input and output types are changed by that flag.
The flag dispatches between two different type signatures.
- with `flat=False` the returning value is an **iterable of tuples**.
**Input is a var args of names** corresponding to the size of the tuple.
The flag value is **usually never provided as a keyword** assuming the
default.
- with `flat=True` the **result is a flat iterable** with an element type
of the requested field. Keyword **righthand side is usually `True`
literal**, I can't imagine code where `flat=<variable>` in practice.
Given that, it seems like there should be separate methods:
- values_list(*names)
- flat_values_list(name)
--
Ticket URL: <https://code.djangoproject.com/ticket/35750>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070191db77655a-b7c64d8f-7fb4-4b08-a2c5-d4dffcca0cc1-000000%40eu-central-1.amazonses.com.