On Tue, Dec 20, 2022 at 8:21 PM Stephen J. Turnbull <stephenjturnbull > > UserStrings are not instances of str though. I think THAT is a bug. > > I guess, although surely the authors of that class thought about it.
Well, kind of — the entire reason for UserString was that at the time, str itself could not be subclassed. So it was certainly a feature at the time ;-) The question is whether anyone thought about it again later, and the docs seem to indicate not: UserString <https://docs.python.org/3/library/collections.html?highlight=userstring#collections.UserString> objects The class, UserString <https://docs.python.org/3/library/collections.html?highlight=userstring#collections.UserString> acts as a wrapper around string objects. The need for this class has been partially supplanted by the ability to subclass directly from str <https://docs.python.org/3/library/stdtypes.html#str>; however, this class can be easier to work with because the underlying string is accessible as an attribute. And it has no docstrings at all -- it doesn't strike me that anyone is putting any thought into carefully maintaining it. Anyway, this could probably be improved with a StringLike ABC I'm not so sure -- in many cases, the underlying C implementation is critical -- and strings are one of those things that generally aren't duck-typed -- subclassing is a special case of that. Anyway -- I've only gotten this far 'cause it caught my interest -- but I have no need for subclassing strings -- but if someone does, I think it would be worth at least bringing up with the core devs. -CHB
_______________________________________________ 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/U6PT3QA4MHXGE2ZIELUM6PK37HM3TICK/ Code of Conduct: http://python.org/psf/codeofconduct/