Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
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 routineEnvironment
- CPython versions: 3.10.2 3.11.0b4 (in Idle and at the prompt)
- Operating system and architecture: Windows 10 64-bit