[New-bugs-announce] [issue31841] Several methods of collections.UserString do not return instances of UserString or its subclasses

Dmitry Kazakov report at bugs.python.org
Sun Oct 22 15:46:35 EDT 2017


New submission from Dmitry Kazakov <waultah at gmail.com>:

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'>

----------
components: Library (Lib)
messages: 304761
nosy: vaultah
priority: normal
severity: normal
status: open
title: Several methods of collections.UserString do not return instances of UserString or its subclasses
type: behavior

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31841>
_______________________________________


More information about the New-bugs-announce mailing list