Skip to content

fix reference to type being borrowed inside #[classmethod] dunder methods - #6420

Merged
davidhewitt merged 3 commits into
PyO3:mainfrom
davidhewitt:class-type
Sep 16, 2026
Merged

davidhewitt merged 3 commits into
PyO3:mainfrom
davidhewitt:class-type

Conversation

@davidhewitt

Copy link
Copy Markdown
Member

While working on #6386 I noticed a questionable call to Py_TYPE inside macro code to create #[classmethod] receivers from instance values. The call didn't increase the refcount of the type object; I'm pretty confident that this could lead to bugs if __class__ was reassigned on the object and it caused the type object to be garbage collected.

I didn't bother writing a test because it'd be pretty painful to hit the problem conditions and it feels like the sort of thing where now it's done correctly we're unlikely to regress it.

@codspeed

codspeed Bot commented Sep 15, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 141 untouched benchmarks
⏩ 6 skipped benchmarks1


Comparing davidhewitt:class-type (c0f835a) with main (6fb0ba8)

Open in CodSpeed

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Icxolu Icxolu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct (and also a bit cleaner)

@davidhewitt
davidhewitt added this pull request to the merge queue Sep 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 16, 2026
@davidhewitt
davidhewitt added this pull request to the merge queue Sep 16, 2026
Merged via the queue into PyO3:main with commit a859d05 Sep 16, 2026
53 checks passed
@davidhewitt
davidhewitt deleted the class-type branch September 16, 2026 07:00
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