On Thu, 2020-04-23 at 14:47 -0400, Kyle Lahnakoski wrote:
<snip>
> I reviewed my code:  of 20,360 keyword arguments, 804 (4%) are have
> the 
> x=x format.  I do not know if this is enough to justify such a
> proposal, 

Is that script somewhere? I got a bit curious and wasted some time on
making my own script to search projects (link at end), and then applied
it on cpython and the scientific python stack.

Likely I simply missed an earlier email that already did this, and
hopefully it is all correct.

For cpython I got:

Scanned 985 python files.
    Total kwargs: 10105 out which identical: 1407
    Thus 13.9% are
identical.

Table of most common identical kwargs:
                 name | value
 ---------------------|------
                 file |    43
             encoding |    42
              context |    36
                 loop |    33
              argname |    31
                 name |    31
               errors |    24
                limit |    21

For the scientific python stack (NumPy, SciPy, pandas, astropy,
sklearn, matplotlib, skimage), I got:

Overall Scanned 1884 python files.
    Total kwargs: 39381 out which identical: 12229
    Thus 31.1% are
identical.

Table of most common identical kwargs:
                 name | value
 ---------------------|------
                 axis |   606
                dtype |   471
                 copy |   296
                  out |   224
                 name |   205
                 mode |   122
           fill_value |   115
         random_state |   114
        sample_weight |   109
              verbose |   106


For example including tests, etc. reduces the percentages considerably
to 10.5% and 15.1% respectively. These are focusing on the main
namespace(s) for the scientific python projects, which exaggerates
things by ~7% as well (your numbers will vary depending on which files
to scan/analyze).
Many of the projects have around 30% in their main namespace, pandas
has 40% outside of tests.

Since I somewhat liked the arguments for `=arg` compared to `arg=` and
I noticed that it is not uncommon to have something like:

    function(..., dtype=arr.dtype)

I included such patterns for fun. The percentages increase to 18.9% or
36.6% (again no tests, etc.) respectively.
Not really suggesting it here, just thought it was interesting :).

It would be interesting how common the patterns are for dictionary
literals if this discussion continues (although I may have missed it,
maybe it was already done).
Another more trickier but very interesting thing, would be to see how
many positional arguments of identical name are passed. If such an
argument is not the first or second, it may be cleaner as kwargs, but
someone opted to not use them, maybe due to being verbose.

Anyway, I am not advocating anything, I was mainly curious. Personally,
I am not yet convinced that any of the syntax proposals are nice when
considering the additional noise of having more (less-common) syntax.

Cheers,

Sebastian


PS: My hacky script is at:
https://gist.github.com/seberg/548a2fa9187739ff33ec406e933fa8a4



> but I would suggest that is a minimum:  Currently there is no
> incentive 
> to have identical names for identical things through a call chain; 
> an 
> incentive will only increase the use of this pattern.
> 
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python-ideas@python.org/message/UQGVKME6PO3RYJE4S2BTRB7L66UB4B6B/
> Code of Conduct: http://python.org/psf/codeofconduct/

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/4FD7LQHTK3LQ7ED2KHAJSMPC2VAYPTRG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to