Dennis Sweeney wrote:
-----------------------
It appears that in CPython, self[:] is self is true for base
str objects, so I think return self[:] is consistent with (1) the
premise that returning self is an implementation detail that is
neither mandated nor forbidden, and (2) the premise that the
methods should return base str objects even when called on str
subclasses.

Ethan Furman wrote:
-------------------
The Python interpreter in my head sees self[:] and returns a copy.

Dennis Sweeney wrote:
-----------------------
I think I'm still in the camp that ``return self[:]`` more precisely
prescribes the desired behavior. It would feel strange to me to write
``return self`` and then say "but you don't actually have to return self,
and in fact you shouldn't when working with subclasses".


I don't understand that list bit -- surely, if I'm bothering to implement
`removeprefix` and `removesuffix` in my subclass, I would also want to
`return self` to keep my subclass?  Why would I want to go through the extra
overhead of either calling my own `__getitem__` method, or have the
`str.__getitem__` method discard my subclass?

However, if you are saying that `self[:]`  *will* call 
`self.__class__.__getitem__`
so my subclass only has to override `__getitem__` instead of `removeprefix` and
`removesuffix`, that I can be happy with.

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

Reply via email to