summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorDamien Caliste <dcaliste@free.fr>2020-03-18 16:36:32 +0100
committerRohit Goswami <rog32@hi.is>2022-06-05 15:38:01 +0000
commit5108f78f3e0491ec4b0f284edce8e9fe7bb10e0e (patch)
treeba914dca86d984427c82689e15dd91575c2aaaf2 /numpy
parente5fcb9d52c1b9d3c9caf067849ad1bba128c7e17 (diff)
downloadnumpy-5108f78f3e0491ec4b0f284edce8e9fe7bb10e0e.tar.gz
ENH: complete the 'vars' list of a module
Add to the 'vars' list of a module missing subroutines or functions listed in the 'body' that have not been explicitely declared 'public' or 'private'.
Diffstat (limited to 'numpy')
-rwxr-xr-xnumpy/f2py/crackfortran.py4
-rw-r--r--numpy/f2py/tests/src/crackfortran/pubprivmod.f9010
-rw-r--r--numpy/f2py/tests/test_crackfortran.py9
3 files changed, 21 insertions, 2 deletions
diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py
index 515bdd787..f1ac15a43 100755
--- a/numpy/f2py/crackfortran.py
+++ b/numpy/f2py/crackfortran.py
@@ -2488,10 +2488,10 @@ def analyzevars(block):
del vars['']
if 'attrspec' in block['vars']['']:
gen = block['vars']['']['attrspec']
- for n in list(vars.keys()):
+ for n in set(vars) | set(b['name'] for b in block['body']):
for k in ['public', 'private']:
if k in gen:
- vars[n] = setattrspec(vars[n], k)
+ vars[n] = setattrspec(vars.get(n, {}), k)
svars = []
args = block['args']
for a in args:
diff --git a/numpy/f2py/tests/src/crackfortran/pubprivmod.f90 b/numpy/f2py/tests/src/crackfortran/pubprivmod.f90
new file mode 100644
index 000000000..46bef7cb9
--- /dev/null
+++ b/numpy/f2py/tests/src/crackfortran/pubprivmod.f90
@@ -0,0 +1,10 @@
+module foo
+ public
+ integer, private :: a
+ integer :: b
+contains
+ subroutine setA(v)
+ integer, intent(in) :: v
+ a = v
+ end subroutine setA
+end module foo
diff --git a/numpy/f2py/tests/test_crackfortran.py b/numpy/f2py/tests/test_crackfortran.py
index ea618bf33..5a83ee7da 100644
--- a/numpy/f2py/tests/test_crackfortran.py
+++ b/numpy/f2py/tests/test_crackfortran.py
@@ -73,6 +73,15 @@ class TestModuleProcedure():
assert mod["body"][3]["implementedby"] == \
["get_int", "get_real"]
+ def test_notPublicPrivate(self, tmp_path):
+ fpath = util.getpath("tests", "src", "crackfortran", "pubprivmod.f90")
+ mod = crackfortran.crackfortran([str(fpath)])
+ assert len(mod) == 1
+ mod = mod[0]
+ assert mod['vars']['a']['attrspec'] == ['private', ]
+ assert mod['vars']['b']['attrspec'] == ['public', ]
+ assert mod['vars']['seta']['attrspec'] == ['public', ]
+
class TestExternal(util.F2PyTest):
# issue gh-17859: add external attribute support