Skip to content

gh-161968: Fall back to the right operand's sq_repeat in PyNumber_InPlaceMultiply - #161969

Merged
StanFromIreland merged 3 commits into
python:mainfrom
Broyojo:gh-161968-inplace-mul-sq-repeat
Nov 14, 2026
Merged

StanFromIreland merged 3 commits into
python:mainfrom
Broyojo:gh-161968-inplace-mul-sq-repeat

Conversation

@Broyojo

@Broyojo Broyojo commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

PyNumber_InPlaceMultiply only fell back to the right operand's sq_repeat when the left operand's type had no tp_as_sequence at all. Heap types always have one, so x *= [1] raised TypeError for int subclasses, IntEnum members and other classes with __index__, although x * [1] worked. The right operand's repeat is now tried whenever the left operand provides no repeat slot, as PyNumber_Multiply does. The right operand is still not repeated in place.

Note: one error message changes. For a left operand with sequence methods but no __index__, such as {} *= [1], the message now matches {} * [1] ("can't multiply sequence by non-int of type 'dict'"). This also matters for gh-149180: if every type gets a tp_as_sequence, plain int *= list would hit the same bug without this fix.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T00:26:18.090897Z 95b0c7a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@StanFromIreland StanFromIreland changed the title gh-161968: Fix x *= seq when x is an instance of a Python class with __index__ gh-161968: Fall back to the right operand's sq_repeat in PyNumber_InPlaceMultiply Nov 14, 2026
@StanFromIreland
StanFromIreland enabled auto-merge (squash) November 14, 2026 10:24
@StanFromIreland
StanFromIreland merged commit fb08c03 into python:main Nov 14, 2026
103 of 105 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants