This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Several methods of collections.UserString do not return instances of UserString or its subclasses
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: lisroach Nosy List: anthony shaw, lisroach, rhettinger, vaultah
Priority: normal Keywords: patch

Created on 2017-10-22 19:46 by vaultah, last changed 2022-04-11 14:58 by admin.

Messages (4)
msg304761 - (view) Author: Dmitry Kazakov (vaultah) * Date: 2017-10-22 19:46
A few of the methods of collections.UserString return objects of type str when one would expect instances of UserString or a subclass. Here's an example for UserString.join:

    >>> s = UserString(', ').join(['a', 'b', 'c']); print(repr(s), type(s))
    'a, b, c' <class 'str'>

This *looks* like a bug to me, but since I was unable to find similar bug reports, and this behaviour has existed for years, I'm not too sure.

Same holds for UserString.format and UserString.format_map, which were added recently (issue 22189):

    >>> s = UserString('{}').format(1); print(repr(s), type(s))
    '1' <class 'str'>

At least, this output is inconsistent with %-based formatting:

    >>> s = UserString('%d') % 1; print(repr(s), type(s))
    '1' <class 'collections.UserString'>
msg304857 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-10-24 04:28
I would support changing format() and format_map().

The join() method has been around for a long time, so changing it might do more harm than good.
msg306726 - (view) Author: Dmitry Kazakov (vaultah) * Date: 2017-11-22 13:04
I added a PR.

FWIW, I still think it would make sense to change the return type of UserString.join, and maybe *split* and *partition methods (to return list/tuple of UserString objects) for the sake of consistency.
msg341536 - (view) Author: anthony shaw (anthony shaw) Date: 2019-05-06 15:35
This issue has been open for some time and the PR references an upstream branch that no longer exists.
Can this request be closed, or has the conversation yet to be resolved?
History
Date User Action Args
2022-04-11 14:58:53adminsetgithub: 76022
2019-05-07 10:28:33vaultahsetpull_requests: - pull_request13067
2019-05-07 10:24:39vaultahsetpull_requests: + pull_request13067
2019-05-06 15:50:15vaultahsetpull_requests: - pull_request4438
2019-05-06 15:35:57anthony shawsetnosy: + anthony shaw
messages: + msg341536
2017-11-22 13:04:32vaultahsetmessages: + msg306726
2017-11-22 12:52:18vaultahsetkeywords: + patch
stage: patch review
pull_requests: + pull_request4438
2017-10-24 04:28:11rhettingersetversions: + Python 3.7
nosy: + lisroach, rhettinger

messages: + msg304857

assignee: lisroach
2017-10-22 19:46:35vaultahcreate