python / python/cpython

UserString subtypes parameterless `__init__`

Open
#131,857 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Description

Subtypes of UserString cannot be initialized without a seq argument as the builtin str can.

Reproduction
from collections import UserString

class MyString(UserString):
    pass
>>> str()
''
>>> MyString()
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    MyString()
    ~~~~~~~~^^
TypeError: UserString.__init__() missing 1 required positional argument: 'seq'
Workaround
from collections import UserString

class MyString(UserString):
    def __init__(self, seq: object = str()) -> None:
        super().__init__(seq)
CPython versions tested on:

3.13

Operating systems tested on:

Linux

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the collections.UserString entry point and reproduce the parameterless-construction example on Python 3.13. Check the UserString initialization behavior and verify that a subclass without its own init can be instantiated like str(), while existing sequence initialization remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.