-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type check for better fortran interface support #182
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this contribution. Looks good from a quick scan apart from the one minor comment noted.
I wasn't able to figure out how this allows polymorphism, but I'll read it again more carefully later before merging.
f90wrap/pywrapgen.py
Outdated
@@ -155,7 +155,8 @@ def _format_line_no(lineno): | |||
class PythonWrapperGenerator(ft.FortranVisitor, cg.CodeGenerator): | |||
def __init__(self, prefix, mod_name, types, f90_mod_name=None, | |||
make_package=False, kind_map=None, init_file=None, | |||
py_mod_names=None, class_names=None, max_length=None): | |||
py_mod_names=None, class_names=None, max_length=None, | |||
type_check=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default value of type_check
should probably be False
, not None
?
OK, I understand the point about polymorphism now. Happy to merge once you fix the minor issue with the |
I fixed the type_check default value. I also reworked a bit the case where the fortran type is not known to f90wrap. |
thank you! I'll wait for the upcoming build improvements before doing a new release. |
This pull request addresses two current limitations:
This pr adds type and shape checks in the python wrapper function. It raises TypeError if the type/shape provided to the python function does not match the type/shape of the wrapped Fortran subroutine.
It allows better support for Fortran interfaces. For instance, it enables one to wrap:
Known limitation: as Fortran
logical
is mapped to Cint
there is no differentiation of pythonbool
andint32
.It should solve issue #107
A command line flag is added to activate those checks, so that old behavior is still possible and is the default.
The flag could be removed so that the checks are always added, but this could break existing code. It does break some tests in the exemple directory, though they seem easily fixable.