[Python-ideas] Improving fn(arg=arg, name=name, wibble=wibble) code

Anders Hovmöller boxed at killingar.net
Thu Sep 13 20:22:44 EDT 2018


>> I’ll repeat myself: what about .format()? If you localize you can’t use
>> f-strings. What about templates in web apps? Obviously f-strings won’t do.
>> What about json blobs in REST APIs? Again no help from f-strings. What about
>> functions with more than 3 arguments generally?
> 
> For f-strings, can't we turn the dictionary into a namespace, like so

I say I’m talking about cases where you can’t use f-strings and you directly talk about f-strings… I think you might have missed the point. 

> For functions with more than 3 arguments, perhaps you could give some
> examples where you'd like improvement.


Sure. Run this script against django: https://gist.github.com/boxed/e60e3e19967385dc2c7f0de483723502 <https://gist.github.com/boxed/e60e3e19967385dc2c7f0de483723502>

It will print all function calls that are positional and have > 2 arguments. Not a single one is good as is, all would be better with keyword arguments. A few of them are pass through as discussed before, but far from all. 

For example:

django-master/django/http/multipartparser.py 225
                                     handler.new_file(
                                    field_name, file_name, content_type,
                                    content_length, charset, content_type_extra,
                                )

That’s positional because keyword is more painful.

/ Anders
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180914/fe2aaa06/attachment.html>


More information about the Python-ideas mailing list