BUG: Show allocatable arrays in `dir()` for f2py modules by HaoZeke · Pull Request #30965 · numpy/numpy · GitHub
Skip to content

BUG: Show allocatable arrays in dir() for f2py modules - #30965

Merged
mattip merged 1 commit into
numpy:mainfrom
HaoZeke:fix/f2py-allocatable-dir
Mar 11, 2026
Merged

mattip merged 1 commit into
numpy:mainfrom
HaoZeke:fix/f2py-allocatable-dir

Conversation

@HaoZeke

@HaoZeke HaoZeke commented Mar 8, 2026

Copy link
Copy Markdown
Member

Add a __dir__ method to PyFortranObject that includes all defs names (routines, variables, and allocatable arrays), not just the keys in the object dict. Previously, allocatable arrays were accessible via getattr but invisible to dir() because PyFortranObject_New only populated the dict with routines and non-allocatable variables.

Closes #27696

cc @2sn (sorry for the long delay)

@HaoZeke
HaoZeke requested a review from melissawm March 8, 2026 15:26
@HaoZeke
HaoZeke force-pushed the fix/f2py-allocatable-dir branch from c7bad11 to 0791365 Compare March 8, 2026 15:35
@HaoZeke HaoZeke changed the title BUG: Show allocatable arrays in dir() for F2PY modules BUG: Show allocatable arrays in dir() for f2py modules Mar 8, 2026
@HaoZeke
HaoZeke force-pushed the fix/f2py-allocatable-dir branch 2 times, most recently from ff3a5f8 to 9a12dbd Compare March 8, 2026 20:17
@mattip

mattip commented Mar 10, 2026

Copy link
Copy Markdown
Member

@HaoZeke
HaoZeke force-pushed the fix/f2py-allocatable-dir branch from 9a12dbd to 7ee18ee Compare March 10, 2026 23:42
@HaoZeke

HaoZeke commented Mar 10, 2026

Copy link
Copy Markdown
Member Author

Makes sense and works nicely.

Thanks for the test ^_^

Why is the test in test_regressions? Did this work once and then stop working?

Ah, no, there was an allocatable array so I reused it while testing, but I've moved it now.

Add a __dir__ method to PyFortranObject that includes variable names
from the defs array (which contains allocatable arrays) alongside the
regular dict keys. Previously dir() only showed dict contents, hiding
allocatable variables that are handled dynamically via getattr.

Closes numpy#27696
@HaoZeke
HaoZeke force-pushed the fix/f2py-allocatable-dir branch from 7ee18ee to 09f1a43 Compare March 10, 2026 23:52
@mattip
mattip merged commit 9c2521b into numpy:main Mar 11, 2026
79 checks passed
@mattip

mattip commented Mar 11, 2026

Copy link
Copy Markdown
Member

@HaoZeke
HaoZeke deleted the fix/f2py-allocatable-dir branch March 11, 2026 10:00
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.

BUG: Allocatable array variables don't show up in dir

2 participants