How about just presenting pseudo code with the caveat that that's for the
base str and bytes classes only, and then stipulating that for subclasses
the return value is still a str/bytes/bytearray instance, and leaving it at
that? After all the point of the Python code is to show what the C code
should do in a way that's easy to grasp -- giving a Python implementation
is not meant to constrain the C implementation to have *exactly* the same
behavior in all corner cases (since that would lead to seriously contorted
C code).

On Fri, Mar 27, 2020 at 1:02 PM Dennis Sweeney <sweeney.dennis...@gmail.com>
wrote:

> I was trying to start with the the intended behavior of the str class,
> then move on to generalizing to other classes, because I think completing a
> single example and *then* generalizing is an instructional style that's
> easier to digest, whereas intermixing all of the examples at once can get
> confused (can I call str.removeprefix(object(), 17)?). Is something missing
> that's not already there in the following sentence in the PEP?
>
> Although the methods on the immutable ``str`` and ``bytes`` types may make
> the aforementioned optimization of returning the original object,
> ``bytearray.removeprefix()`` and ``bytearray.removesuffix()`` should always
> return a copy, never the original object.
>
> Best,
> Dennis
> _______________________________________________
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/IO33NJUQTN27TU342NAJAAMR7YGEPQRE/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/RTK46ZXQYPWVRJIWPAD3EXTJBSU27VKF/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to