Skip to content
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

default parameters vs export specifications #2056

Open
nbecker opened this issue Dec 5, 2022 · 1 comment
Open

default parameters vs export specifications #2056

nbecker opened this issue Dec 5, 2022 · 1 comment

Comments

@nbecker
Copy link
Contributor

nbecker commented Dec 5, 2022

I think there is an incompatibility between functions with default parameter values and pythran specifications. Here is an example:

#pythran export F(int, float, str)
def F(a=1, b=2.0, c='hello'):
    print ('a:', a, 'b:', b, 'c:', c)
from _default import F

In [23]: F()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[23], line 1
----> 1 F()

TypeError: Invalid call to pythranized function `F()'
Candidates are:

    - F(int, float, str)

In python, any combination of values could be specified or omitted:
F(a=1)
F(b=2.5)
F(b=3.0, c='bye')
There would appear to be no way to capture this in
pythran_export specifications.

For now, my workaround is write python wrapper functions that interpret the passed parameters and defaults and then call the pythran function with all parameters passed.

def wrap_F (a=1, b=2.0, c='hello'):
    return F(a, b, c)

But this is not ideal

At least it would be better if somehow the wrapper function could be included in the same source file instead of needing a 2nd source file for the wrapper.

@pdumon
Copy link

pdumon commented Dec 9, 2022

optional args can be specified with a ? but that would not solve your case. Don't know about kwargs.

#pythran export F(int?, float?, str?)
def F(a=1, b=2.0, c='hello'):
    print ('a:', a, 'b:', b, 'c:', c)

can be called with e.g. F(5), F(3, 4.0) etc, but not with F(b=3.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants