8000 Merge pull request #25212 from HaoZeke/fixScipyUseblock · numpy/numpy@47b2a9b · GitHub
[go: up one dir, main page]

Skip to content

Commit 47b2a9b

Browse files
authored
Merge pull request #25212 from HaoZeke/fixScipyUseblock
BUG: Don't try to grab callback modules
2 parents 6031da1 + cd049a8 commit 47b2a9b

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

numpy/f2py/auxfuncs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,5 +943,5 @@ def getuseblocks(pymod):
943943
for inner in pymod['body']:
944944
for modblock in inner['body']:
945945
if modblock.get('use'):
946-
all_uses.extend([x for x in modblock.get('use').keys()])
946+
all_uses.extend([x for x in modblock.get("use").keys() if "__" not in x])
947947
return all_uses
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SUBROUTINE FOO(FUN,R)
2+
EXTERNAL FUN
3+
INTEGER I
4+
REAL*8 R, FUN
5+
Cf2py intent(out) r
6+
R = 0D0
7+
DO I=-5,5
8+
R = R + FUN(I)
9+
ENDDO
10+
END
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
python module __user__routines
2+
interface
3+
function fun(i) result (r)
4+
integer :: i
5+
real*8 :: r
6+
end function fun
7+
end interface
8+
end python module __user__routines
9+
10+
python module callback2
11+
interface
12+
subroutine foo(f,r)
13+
use __user__routines, f=>fun
14+
external f
15+
real*8 intent(out) :: r
16+
end subroutine foo
17+
end interface
18+
end python module callback2

numpy/f2py/tests/test_callback.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,16 @@ def foo(x):
228228

229229
r = self.module.gh18335(foo)
230230
assert r == 123 + 1
231+
232+
233+
class TestGH25211(util.F2PyTest):
234+
sources = [util.getpath("tests", "src", "callback", "gh25211.f"),
235+
util.getpath("tests", "src", "callback", "gh25211.pyf")]
236+
module_name = "callback2"
237+
238+
def test_gh18335(self):
239+
def bar(x):
240+
return x*x
241+
242+
res = self.module.foo(bar)
243+
assert res == 110

0 commit comments

Comments
 (0)
0