8000 TST: Add an F2PY check for exposing variables without functions by HaoZeke · Pull Request #27730 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TST: Add an F2PY check for exposing variables without functions #27730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/release/upcoming_changes/27695.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
``f2py`` handles multiple modules and exposes variables again
-------------------------------------------------------------
A regression has been fixed which allows F2PY users to expose variables to
Python in modules with only assignments, and also fixes situations where
multiple modules are present within a single source file.
25 changes: 25 additions & 0 deletions numpy/f2py/tests/src/regression/assignOnlyModule.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
MODULE MOD_TYPES
INTEGER, PARAMETER :: SP = SELECTED_REAL_KIND(6, 37)
INTEGER, PARAMETER :: DP = SELECTED_REAL_KIND(15, 307)
END MODULE
!
MODULE F_GLOBALS
USE MOD_TYPES
IMPLICIT NONE
INTEGER, PARAMETER :: N_MAX = 16
INTEGER, PARAMETER :: I_MAX = 18
INTEGER, PARAMETER :: J_MAX = 72
REAL(SP) :: XREF
END MODULE F_GLOBALS
!
SUBROUTINE DUMMY ()
!
USE F_GLOBALS
USE MOD_TYPES
IMPLICIT NONE
!
REAL(SP) :: MINIMAL
MINIMAL = 0.01*XREF
RETURN
!
END SUBROUTINE DUMMY
12 changes: 12 additions & 0 deletions numpy/f2py/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,15 @@ def test_gh25784():
)
except ImportError as rerr:
assert "unknown_subroutine_" in str(rerr)


@pytest.mark.slow
class TestAssignmentOnlyModules(util.F2PyTest):
# Ensure that variables are exposed without functions or subroutines in a module
sources = [util.getpath("tests", "src", "regression", "assignOnlyModule.f90")]

@pytest.mark.slow
def test_gh27167(self):
assert (self.module.f_globals.n_max == 16)
assert (self.module.f_globals.i_max == 18)
assert (self.module.f_globals.j_max == 72)
Loading
0