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

Michael Selik mike at selik.org
Thu Sep 13 22:07:33 EDT 2018


On Thu, Sep 13, 2018 at 5:22 PM Anders Hovmöller <boxed at killingar.net>
wrote:

> For example:
> django-master/django/http/multipartparser.py 225
>

Sorry, I didn't recognize this as a link on first read. I'll provide a link
here to the code in context.

https://github.com/django/django/blob/e7a0a5c8b21f5ad1a0066bd0dfab84466b474e15/django/http/multipartparser.py#L225

This is a fairly large function that might benefit from being refactored to
clarify the code. On the other hand, I don't advocate creating too many
helper functions with only one callsite. The one thing that catches my eye
is the repeated use of ``exhaust`` in the else clause to several layers of
the nested try and if blocks.

It's a bit too large for me to make sense of it quickly. My apologies for
not offering a holistic refactor.

That’s positional because keyword is more painful.
>

Why would keyword arguments be more painful here? They've already split the
call across 4 lines. Why not go a bit further and use keyword args to make
it 6 or 7 lines? Maybe they decided it reads fine as it is.


Sure. Run this script against django:
> 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.
>

I disagree. Please expand your assertion by explaining why an example is
not good as-is and would be better with keyword arguments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180913/feb3493b/attachment.html>


More information about the Python-ideas mailing list