Python 2 does not support named arguments after *fields, and raises a 
SyntaxError. As long as Django supports Python 2, we're stuck with the 
current approach. I'm sure the new style will be used once Python 2 support 
is dropped.

On Thursday, December 15, 2016 at 1:40:02 PM UTC+1, Alexey Gerasimov 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)
>         clone._iterable_class = FlatValuesListIterable if flat else 
> ValuesListIterable
>         return clone
>
>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/c35a620c-e864-446c-99fc-93d8af407943%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to