jameskermode/f90wrap

Wrong module class name in a call to `f90wrap.runtime.FortranDerivedTypeArray`

opeil opened this issue · 2 comments

opeil commented

With renaming of module/derived type via class_names.json the wrapper generates a wrong Python code for the array of derived types. An example of the incorrectly generate code:

            self.partial_energies = f90wrap.runtime.FortranDerivedTypeArray(self,
                                            _wrap.f90wrap_lattice_site_output__array_getitem__partial_energies,
                                            _wrap.f90wrap_lattice_site_output__array_setitem__partial_energies,
                                            _wrap.f90wrap_lattice_site_output__array_len__partial_energies,
                                            """
            Element partial_energies ftype=type(dft_energy) pytype=Dft_Energy
            
            
            Defined at ../main/lattice_site_output.f90 line 52
            
            """, Dft_Energy_Mod.DFTEnergy)

where the last line is expected to contain dft_energy_mod.DFTEnergy in accordance with renaming rules in class_names.

The issue seems to boil down to line 729 of pywrapgen.py (construction of a dict of function arguments) which refers to cls_mod_name.title(). Since in all other places cls_mod_name is used without .title() I suspect that this is a bug. A simple fix below resolves the issue.

diff --git a/f90wrap/pywrapgen.py b/f90wrap/pywrapgen.py
index f83461d..c3c5144 100644
--- a/f90wrap/pywrapgen.py
+++ b/f90wrap/pywrapgen.py
@@ -726,7 +726,7 @@ return %(el_name)s""" % dct)
                    parent='self',
                    doc=format_doc_string(el),
                    cls_name=cls_name,
-                   cls_mod_name=cls_mod_name.title() + '.')
+                   cls_mod_name=cls_mod_name + '.')
 
         if isinstance(node, ft.Module):
             dct['parent'] = 'f90wrap.runtime.empty_type'

This is just a one-line change but if necessary I can make a PR.

Thanks for reporting and digging into this. Do make a PR then we can see if your proposed change causes any regressions in the test suite.

opeil commented

I have create a PR but unfortunately I was not able to run the tests myself because they seem to be incomplete (files are missing).
Edit: I have remembered now that tests are actually in examples. All these tests pass on my laptop.