f90wrap
f90wrap copied to clipboard
Issues when renaming python keywords
@jameskermode I realized that f90wrap
will try to rename Fortran variables/procedures that are conflicting with the python keywords. This is smart. But I think we should use the original name (without the underscore) when pointing the original variable. I got the following error when wrapping a variable lambda
.
mpifort:f90: f90wrap_regcoil_variables.f90
f90wrap_regcoil_variables.f90:2265:32:
2265 | use regcoil_variables, only: regcoil_variables_lambda_ => lambda_
| 1
Error: Symbol 'lambda_' referenced at (1) not found in module 'regcoil_variables'
Any thoughts to a quick fix?
The source code of f90wrap
for the renaming is
class RenameReservedWords(ft.FortranVisitor):
.
.
.
# rename Python keywords by appending an underscore
import keyword
self.name_map.update(dict((key, key + '_') for key in keyword.kwlist))
I have a similar problem with a field named As
:
@as_.setter
def as_(self, as_):
_pyhmcode.f90wrap_halomod__set__as_(self._handle, as_)
AttributeError: module '_pyhmcode' has no attribute 'f90wrap_halomod__set__as_'
Replacing this with
@as_.setter
def as_(self, as_):
_pyhmcode.f90wrap_halomod__set__as(self._handle, as_)
works. So it seems like in my case the underscore is only added on the python side but not the Fortran wrapper.