Skip to content

BUG: f2py regression #28014

@germasch

Description

@germasch

Describe the issue:

numpy==2.2.0 crashes (2.1.3 is fine) on the example code below. I tracked this down to #27728, which ends up not lower-casing the IU on the integer :: IU line, due to the following line having a !f2py directive.

Reproduce the code example:

$ cat > repro_lower.F90 <<EOF
subroutine inquire_next(IU)
   IMPLICIT NONE
   integer :: IU
   !f2py intent(in) IU

end subroutine
EOF

$ python -m numpy.f2py -m _repro_lower repro_lower.F90 --lower

Error message:

[...]
getctype: No C-type found in "{'attrspec': [], 'intent': ['in']}", assuming void.
getctype: No C-type found in "{'attrspec': [], 'intent': ['in']}", assuming void.
getctype: No C-type found in "{'attrspec': [], 'intent': ['in']}", assuming void.
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/workspaces/openggcm/.venv/lib/python3.10/site-packages/numpy/f2py/__main__.py", line 5, in <module>
    main()
  File "/workspaces/openggcm/.venv/lib/python3.10/site-packages/numpy/f2py/f2py2e.py", line 783, in main
    run_main(sys.argv[1:])
  File "/workspaces/openggcm/.venv/lib/python3.10/site-packages/numpy/f2py/f2py2e.py", line 507, in run_main
    ret = buildmodules(postlist)
  File "/workspaces/openggcm/.venv/lib/python3.10/site-packages/numpy/f2py/f2py2e.py", line 412, in buildmodules
    dict_append(ret[name], rules.buildmodule(module, um))
  File "/workspaces/openggcm/.venv/lib/python3.10/site-packages/numpy/f2py/rules.py", line 1300, in buildmodule
    api, wrap = buildapi(nb)
  File "/workspaces/openggcm/.venv/lib/python3.10/site-packages/numpy/f2py/rules.py", line 1478, in buildapi
    vrd = capi_maps.sign2map(a, var[a])
  File "/workspaces/openggcm/.venv/lib/python3.10/site-packages/numpy/f2py/capi_maps.py", line 583, in sign2map
    ret['pydocsign'], ret['pydocsignout'] = getpydocsign(a, var)
  File "/workspaces/openggcm/.venv/lib/python3.10/site-packages/numpy/f2py/capi_maps.py", line 377, in getpydocsign
    sig = '%s : %s %s%s' % (a, opt, c2py_map[ctype], init)
KeyError: 'void'

Python and NumPy Versions:

2.2.0
3.10.12 (main, Nov 6 2024, 20:22:13) [GCC 11.4.0]

Runtime Environment:

No response

Context for the issue:

I can work around it by lower-casing the variable name in the Fortran source, but this bug looks like it may have broad impacts on f2py users, and (ask me how I know) it wasn't trivial to even track down the source of the breakage to the latest numpy being pulled into pip's build environment.

I did track it down to commit ab3aee3, and I think the breakage was partially fixed by c95c2f0, but I'd think the proper fix might be to not lower-case f2py directives, but still lower-case the Fortran code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions