On 15 Dec 2016, at 15:39, Alexey Gerasimov <lokomot476@gmail.com> wrote:Why "flat" keyword is accepted that way? Why not just as def values_list(self, *fields, flat=False)? Because of that I cannot have support in my IDE (autocomplete)
def values_list(self, *fields, **kwargs):
flat = kwargs.pop('flat', False)
if kwargs:
raise TypeError('Unexpected keyword arguments to values_list: %s' % (list(kwargs),))
if flat and len(fields) > 1:
raise TypeError("'flat' is not valid when values_list is called with more than one field.")
_fields = []
expressions = {}
for field in fields:
if hasattr(field, 'resolve_expression'):
field_id = str(id(field))
expressions[field_id] = field
_fields.append(field_id)
else:
_fields.append(field)
clone = self._values(*_fields, **expressions) return clone
clone._iterable_class = FlatValuesListIterable if flat else ValuesListIterable --
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/237365e6-2566-4ef3-b86a-005487afb5b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thursday, December 15, 2016
Re: Strange named parameter passing style
Probably for adding other arguments later without braking function signature? I'm with you on this one, though. Using kwargs everywhere it's possible really helps developing using Django. Maybe this is a subject for django-developers@googlegroups.com.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment