
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#coll...> objects The class, UserString <https://docs.python.org/3/library/collections.html?highlight=userstring#coll...> 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