Skip to content

gh-156963: Raise TypeError when concatenating complexstr with another type - #156964

Open
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-curses-complexstr-concat-typeerror
Open

gh-156963: Raise TypeError when concatenating complexstr with another type#156964
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-curses-complexstr-concat-typeerror

Conversation

@fedonman

@fedonman fedonman commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

complexstr_concat() is installed as Py_sq_concat and returned Py_NotImplemented for a non-complexstr operand, but PyNumber_Add() checks for NotImplemented only on the nb_add path and returns an sq_concat result verbatim, so the singleton reached Python code and s += 'x' rebound the name to it. It now raises TypeError, matching the two tp_richcompare slots that use the protocol where it does apply. __radd__ is unaffected, since PyNumber_Add() tries nb_add on both operands before falling back to sq_concat.

There is no NEWS entry because complexstr is new in 3.16 and unreleased, so no user could hit this.

…nother type

complexstr_concat() is the sq_concat slot and returned NotImplemented
for a non-complexstr operand.  PyNumber_Add() returns an sq_concat
result verbatim, so the singleton reached Python code instead of a
TypeError, and an augmented assignment rebound the name to it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant