diff options
| author | Damien Caliste <dcaliste@free.fr> | 2020-03-27 14:35:42 +0100 |
|---|---|---|
| committer | Damien Caliste <dcaliste@free.fr> | 2021-10-01 16:13:22 +0200 |
| commit | f2eccaac3d08c71eb936e18b4f6a5a656b2763d6 (patch) | |
| tree | 48ad5c8680b4e31e3c83225d386247d221882008 /numpy | |
| parent | acb0e9eb57674288ef18bf39908026bc4f42c4a4 (diff) | |
| download | numpy-f2eccaac3d08c71eb936e18b4f6a5a656b2763d6.tar.gz | |
BUG: avoid infinite recurrence on dependencies in crackfortran
Diffstat (limited to 'numpy')
| -rwxr-xr-x | numpy/f2py/crackfortran.py | 4 | ||||
| -rw-r--r-- | numpy/f2py/tests/test_crackfortran.py | 17 |
2 files changed, 20 insertions, 1 deletions
diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py index 661806645..67675af45 100755 --- a/numpy/f2py/crackfortran.py +++ b/numpy/f2py/crackfortran.py @@ -2227,7 +2227,9 @@ def _get_depend_dict(name, vars, deps): if '=' in vars[name] and not isstring(vars[name]): for word in word_pattern.findall(vars[name]['=']): - if word not in words and word in vars: + # The word_pattern may return values that are not + # only variables, they can be string content for instance + if word not in words and word in vars and word != name: words.append(word) for word in words[:]: for w in deps.get(word, []) \ diff --git a/numpy/f2py/tests/test_crackfortran.py b/numpy/f2py/tests/test_crackfortran.py index b1503c1e0..039e085b4 100644 --- a/numpy/f2py/tests/test_crackfortran.py +++ b/numpy/f2py/tests/test_crackfortran.py @@ -264,3 +264,20 @@ class TestDimSpec(util.F2PyTest): # the same sized array sz1, _ = get_arr_size(n1) assert sz == sz1, (n, n1, sz, sz1) + + +class TestModuleDeclaration(): + def test_dependencies(self, tmp_path): + f_path = tmp_path / "mod.f90" + with f_path.open('w') as ff: + ff.write(textwrap.dedent("""\ + module foo + type bar + character(len = 4) :: text + end type bar + type(bar), parameter :: abar = bar('abar') + end module foo + """)) + mod = crackfortran.crackfortran([str(f_path)]) + assert len(mod) == 1 + assert mod[0]['vars']['abar']['='] == "bar('abar')" |
