Skip to content

Instances of UserString cannot be used with str.join #122524

@ricardobranco777

Description

@ricardobranco777

Bug report

Bug description:

from collections import UserString

class Str(UserString):
    def __init__(self, s):
        self.data = s

s = Str("abc")
s2 = Str("def")
print(s)
print(" ".join([s, s2]))

Output:

abc
Traceback (most recent call last):
  File "/tmp/s.py", line 11, in <module>
    print(" ".join([s, s2]))
          ^^^^^^^^^^^^^^^^^
TypeError: sequence item 0: expected str instance, Str found

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions