ENH: Make PyFortranObject a heap type#31598
Open
da-woods wants to merge 3 commits into
Open
Conversation
... and also adapt it to work as an opaque object. The main reason for this is to support the Limited API. I don't think there's much value in keeping it as a static type outside the Limited API - it isn't possible to inherit from it so there shouldn't be many user-observable differences. I'm treating "fortranobject.h" as semi-public. It'll mainly be consumed by f2py modules but presumably people could manually link to it and use it. With that in mind I tried to keep `PyFortran_Type` working via a macro. Additionally, I spotted that it really should be a GC type (because it contains a dictionary with arbitrary contents) and so added that as well.
da-woods
commented
Jun 10, 2026
| }; | ||
|
|
||
| static PyType_Spec fortran_spec = { | ||
| .name = "<f2py internal>.fortran", |
Contributor
Author
There was a problem hiding this comment.
The representation of the type name is a small observable change (although I don't think an important one).
If I just leave it as "fortran" then there's a deprecation warning on import "builtin type %.200s has no __module__ attribute". Setting it to anything else means it's observable if you do print(type(some_fortran_object)).
The solution involves either a custom metaclass as a base type, or a custom class as a descriptor for __module__. We did the metaclass in Cython because the module name was a bit important for pickle-ability, but I don't believe that's a concern here.
So my view is that this doesn't matter, but it is an observable change.
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.
PR summary
... and also adapt it to work as an opaque object.
The main reason for this is to support the Limited API. I don't think there's much value in keeping it as a static type outside the Limited API - it isn't possible to inherit from it so there shouldn't be many user-observable differences.
I'm treating "fortranobject.h" as semi-public. It'll mainly be consumed by f2py modules but presumably people could manually link to it and use it. With that in mind I tried to keep
PyFortran_Typeworking via a macro.Additionally, I spotted that it really should be a GC type (because it contains a dictionary with arbitrary contents) and so added that as well.
AI Disclosure
No AI usage