[issue39574] str.__doc__ is misleading
New submission from Zachary Westrick
Steven D'Aprano
Eric V. Smith
Steven D'Aprano
Change by Eric V. Smith
Eric V. Smith
Serhiy Storchaka
Steven D'Aprano
Serhiy Storchaka
added the comment: See a discussion on Python-Dev: https://mail.python.org/archives/list/python-dev@python.org/message/YMIGWRUE...
I don't know whether the very odd calls
str(encoding='spam')
str(errors='eggs')
str(encoding='spam', errors='eggs')
are intentional or not. I suspect not: to me, it looks like an accident
of implementation, not a deliberate feature. Under what circumstances
would somebody intentionally provide an encoding and error handler when
they aren't actually going to use them? There may be really unusual
cases:
args = () if condition else (mybytes,)
str = str(*args, encoding='spam')
but I doubt they are going to be either common or something we ought to
encourage. Regardless of whether we deprecate and remove those three odd
cases or not, I don't think we should bother documenting them.
If anyone disagrees, and wants to document them, that's okay, but you
can document them as a separate PR with a separate discussion. Let's
just fix the confusion over the default encoding here and worry about
other issues later. Don't let the perfect get in the way of the good
enough for now :-)
----------
_______________________________________
Python tracker
Eric V. Smith
Change by Terry J. Reedy
Steven D'Aprano
pull_request: https://github.com/python/cpython/pull/18401
[Serhiy]
Is not "or both" redundant?
I don't think so. In regular English, "or" can imply exclusive-or: "Shall we eat at the Thai or the Italian restaurant?" There are four relevant cases: - supply neither encoding nor errors; - supply only encoding; - supply only errors; - supply both encoding and errors. Using "or" may be, for some readers, ambiguous: is the last option included or not? For the sake of two extra words, let's make it clear and unambiguous. [Serhiy]
Use just 'utf-8' instead of sys.getdefaultencoding(). It is a constant in Python 3.
I didn't know that. I'm okay with that change, thank you. [Serhiy]
- str(bytes_or_buffer[, encoding[, errors]]) -> str + str(bytes_or_buffer, encoding='utf-8', errors='strict') -> str
I'm happy with that.
Thank you everyone, and sorry again that I have trouble with the Github
process. (I need a new computer with a newer OS.)
----------
_______________________________________
Python tracker
participants (5)
-
Eric V. Smith
-
Serhiy Storchaka
-
Steven D'Aprano
-
Terry J. Reedy
-
Zachary Westrick