More robust Limited API SetItemOnTypeDict#6325
Merged
scoder merged 7 commits intocython:masterfrom Aug 5, 2024
Merged
Conversation
Instead of relying of PyObject_GenericSetAttr (which looks to have been updated in Python 3.14 to ban this usage) we instead work out where the type dict is from __dictoffset__ and manipulate that.
scoder
reviewed
Aug 4, 2024
Contributor
scoder
left a comment
There was a problem hiding this comment.
That's a smart implementation. Nice.
Cython/Utility/ExtensionTypes.c
Outdated
Comment on lines
+699
to
+700
| // TODO - if we ever support custom metatypes for extension types then | ||
| // we have to drop this caching. |
Contributor
There was a problem hiding this comment.
… or use it only for if the type's type is exactly type. That would still catch the majority of extension types. The rest can then hopefully live with a penalty.
Contributor
Author
There was a problem hiding this comment.
I've just changed the comment here for now.
That'd work as a solution, but doesn't seem worth implementing until we need it.
Co-authored-by: scoder <[email protected]>
and take a bit more care about dictoffset edge cases (mostly just raising an error for now)
scoder
reviewed
Aug 5, 2024
filmor
added a commit
to pythonnet/pythonnet
that referenced
this pull request
Dec 7, 2025
Python 3.14 introduced a new assertion that prevents us from using PyObject_GenericSetAttr directly in our meta type. To work around this, we manipulate the type dict directly. This workaround is a simplified variant of Cython's workaround from cython/cython#6325. The relevant Python change is in python/cpython#118454
filmor
added a commit
to pythonnet/pythonnet
that referenced
this pull request
Dec 8, 2025
Python 3.14 introduced a new assertion that prevents us from using PyObject_GenericSetAttr directly in our meta type. To work around this, we manipulate the type dict directly. This workaround is a simplified variant of Cython's workaround from cython/cython#6325. The relevant Python change is in python/cpython#118454
filmor
added a commit
to pythonnet/pythonnet
that referenced
this pull request
Dec 8, 2025
Python 3.14 introduced a new assertion that prevents us from using PyObject_GenericSetAttr directly in our meta type. To work around this, we manipulate the type dict directly. This workaround is a simplified variant of Cython's workaround from cython/cython#6325. The relevant Python change is in python/cpython#118454
filmor
added a commit
to pythonnet/pythonnet
that referenced
this pull request
Dec 8, 2025
Python 3.14 introduced a new assertion that prevents us from using PyObject_GenericSetAttr directly in our meta type. To work around this, we manipulate the type dict directly. This workaround is a simplified variant of Cython's workaround from cython/cython#6325. The relevant Python change is in python/cpython#118454
filmor
added a commit
to pythonnet/pythonnet
that referenced
this pull request
Dec 8, 2025
Python 3.14 introduced a new assertion that prevents us from using PyObject_GenericSetAttr directly in our meta type. To work around this, we manipulate the type dict directly. This workaround is a simplified variant of Cython's workaround from cython/cython#6325. The relevant Python change is in python/cpython#118454
filmor
added a commit
to pythonnet/pythonnet
that referenced
this pull request
Dec 9, 2025
Python 3.14 introduced a new assertion that prevents us from using PyObject_GenericSetAttr directly in our meta type. To work around this, we manipulate the type dict directly. This workaround is a simplified variant of Cython's workaround from cython/cython#6325. The relevant Python change is in python/cpython#118454
filmor
added a commit
to pythonnet/pythonnet
that referenced
this pull request
Feb 24, 2026
Python 3.14 introduced a new assertion that prevents us from using PyObject_GenericSetAttr directly in our meta type. To work around this, we manipulate the type dict directly. This workaround is a simplified variant of Cython's workaround from cython/cython#6325. The relevant Python change is in python/cpython#118454
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Instead of relying of PyObject_GenericSetAttr (which looks to have been updated in Python 3.14 to ban this usage) we instead work out where the type dict is from
__dictoffset__and manipulate that.Fixes #6323