[Python-Dev] Re: Accepting PEP 618: zip(strict=True)

2020年6月19日 01:13:16 -0700

19.06.20 02:57, Guido van Rossum пише:
On Thu, Jun 18, 2020 at 2:36 PM Eric Fahlgren <[email protected] <mailto:[email protected]>> wrote:
 We've implemented the new zip in our sitecustomize.py, and think the
 keyword makes it easier. I've instructed our development staff to
 examine all use of zip as they come across them and add either
 "strict=True" or "strict=False" when they've determined which is
 appropriate. Any zip calls without an explicit "strict=" will be
 deemed "unknown" and requiring further investigation.
That's actually a really nice validation of the choice to use a keyword -- none of the other options debated (which were all variations on "give the alternate behavior a different name") would offer the opportunity to state "I've thought about it and it's definitely okay that the iterables have different lengths at this call site." Sure, in most places this would just look redundant, but in large corporate code bases that's exactly the kind of thing that people like to do.
I did not participate in the recent debates, but in the initial discussion it was proposed to add zip_equal() and zip_shortest() as an alias of zip() (with possibility of changing the behavior of zip() in distant future). There are several advantages of a different name over a boolean keyword argument.
1. It is easier to search in the code.
2. It is easier to replace.
3. It looks more distinguishable.
4. It is faster to call function with positional arguments that with keyword arguments (at the level of bytecode and at the level of parsing arguments).
5. And the implementation is simpler.
Of course the ship is already sailed, but I was surprised that the keyword variant won, while it was not popular initially.
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/NIT7I6SIXBXUBR3HUAW7DLMAQUYUPHM6/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to