Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Custom str subclass as keyword argument leads to System Error #94938

Closed
Assignees
serhiy-storchaka
Labels
3.10only security fixes3.11only security fixes3.12only security fixestopic-argument-clinictype-bugAn unexpected behavior, bug, or error
@jeff5

Description

@jeff5

When arguments are given by keyword using a dictionary, CPython requires that the key be of typestr, or a sub-class. If a customstr subclass defines a badly-behaved__eq__, and is used that way, aSystemError (null argument) can result, which is not expected in the interpreter.

This report stems froma discussion on discuss.python.org about the types of keyword that ought to be allowed -- it's not code I actually want to run.

Reproducer

# kwargsbomb.py Use of a str subclass as a keywordclass S(str):    def __eq__(self, other):        print(other)        return True    def __hash__(self):        return 42u = "my.domain.name"a = u.split(**{'sep':'.'})     # okprint(a)b = u.split(**{S('sep'):'.'})  # okprint(b)c = u.split(**{S('xxx'):'.'})  # failsprint(c)

Output

['my', 'domain', 'name']['my', 'domain', 'name']sepTraceback (most recent call last):  File " ... \kwargsbomb.py", line 18, in <module>    c = u.split(**{S('xxx'):'.'})  # fails        ^^^^^^^^^^^^^^^^^^^^^^^^^SystemError: null argument to internal routine

Environment

  • CPython versions: 3.10.2 3.11.0b4 (in Idle and at the prompt)
  • Operating system and architecture: Windows 10 64-bit

Metadata

Metadata

Labels

3.10only security fixes3.11only security fixes3.12only security fixestopic-argument-clinictype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp