Implement multiple dispatch #1334
Replies: 5 comments 35 replies
-
Blocked by #886 |
Beta Was this translation helpful? Give feedback.
-
@yguclu This issue was opened following a discussion with you and @ratnania . Why has it been converted to a discussion? |
Beta Was this translation helpful? Give feedback.
-
An alternative to the It works like this: from functools import singledispatch
@singledispatch
def func(val):
raise NotImplementedError
@func.register
def _(val: str):
print('This is a string')
@func.register
def _(val: int):
print('This is an int') This seems like something that would be easy to print, although it requires slightly more effort to parse. However I'm not sure how NumPy types should be managed |
Beta Was this translation helpful? Give feedback.
-
We can use the |
Beta Was this translation helpful? Give feedback.
-
I do think we should try and find a solution to this though. This issue comes back repeatedly. Currently we have 4 suggestions:
|
Beta Was this translation helpful? Give feedback.
-
Describe the bug
Sometimes we want different functions to run different methods depending on the type. In python this is often handled with the
isinstance
decorator, however in pyccel this would be unmanageable. We would therefore prefer to use multiple dispatch. Implementation of this would fix issue #802Test Code
Provide code which does not currently work but which should do when this issue is fixed:
The dispatch decorator can either be written ourselves in pyccel or we could add a dependency to multipledispatch (last pypi update Jun 2023)
This code should be translated to an
Interface
. In C and fortran this should work out of the box, in python we need to print the individual functions with the dispatch decorator when necessary. Ideally these functions should be grouped if the code is identical. E.g:Beta Was this translation helpful? Give feedback.
All reactions