Kirill Balunov writes:

 > Also I don't think that comparison with .rstrip() discussion is
 > fair - because in that case, it was proposed to switch two
 > completely different approaches (to treat as string vs to treat as
 > set of chars) which is too much for just a switch thorugh
 > argument. While in zip case it is just how boundaries are treated.

You're missing the topic of the comparison.  It is that we could have

    removeaffix(source, affix, suffix=True)
    strip(self, chars, where='both')       # where in {both, left, right}

rather than

    removesuffix(source, suffix)
    removeprefix(source, prefix)
    strip(self, chars)
    lstrip(self, chars)
    rstrip(self, chars)

I'm not sure why David compares this to the case of print(), where end
and sep are arbitrary strings.  Ditto open(), where the mode argument
is not 2-valued, but (text, binary) X (read, write, append,
create_no_truncate) X (update, not) X (universal newline, not).  Not
only that, but there are other 'mode' arguments such as encoding,
errors, and closefd.

The convention is that rather than a function foo(..., mode) where
mode takes values from a "very small" enum, say {bar, baz, default},
it's preferable to have foo, foo_bar, and foo_baz.  I'd guess #enum=4
(including default) is about the limit, which is why open has all
those enumerated mode arguments: even errors has more than 4 options.
There are just too many of them to define separate functions for all
of them, even for those like encoding and errors that the great
majority of the time take literal strings from a well-defined set.

There's also the qualification that the majority of calls should take
a specific value rather than a variable, and this is the case here.
The use cases for zip_strict and zip_longest that I can think *always*
want mode='strict' or mode='longest'; I can't think of any cases where
I'd call it like

    zip(x, y, mode=choose_mode(x, y), fillvalue=foo)

Once again, this is a convention.  You could have mode arguments, and
many languages prefer them.  There's a certain consistency to that
practice, since the boundary in Python of where it's appropriate to
have separate functions and where a mode argument is better style is
quite fuzzy.  I happen to like the Python practice, but certainly,
tastes can differ in this matter.

Steve
_______________________________________________
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/VYKWIMCL6RGS6WJAI3SK2MIZD7CODPH6/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to