You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide a way to reference current class for intstance methods #95
As expected, we have NameError: name 'MyDummyNumber' is not defined here, which is not multipledispatch issue, but Python one.
There are many ugly ways to workaround this. Then beautiful way is needed!
However multipledispatch works during runtime, so I think that it is potentially possible to specify "current class" during dispatching definition, like following:
changed the title [-]Suggest a way to reference current class for intstance methods[/-][+]Provide a way to reference current class for intstance methods[/+]on Nov 17, 2018
This is supported in my patched version at #78 through lambda functions. No agreement has been reached on possible integration. Have a look if that could be helpful.
Just ran into the same problem. Any progress on this?
@Mystic-Mirage's PR seems to be consistent with annotations currently in use, which employ stringified type names when a forward declaration is needed. So in the case of @dluciv's example, one would simply write
Another possible solution would be to use the Self type introduced by PEP 673, but that also does not work with the current implementation of multipledispatch.
Activity
[-]Suggest a way to reference current class for intstance methods[/-][+]Provide a way to reference current class for intstance methods[/+]francesco-ballarin commentedon Nov 17, 2018
This is supported in my patched version at #78 through lambda functions. No agreement has been reached on possible integration. Have a look if that could be helpful.
dluciv commentedon Nov 17, 2018
A great way as for me, waiting to get it in new releases. Thank you!
May be it is even useful to define identical function inside
multidispatchmodule, as Python lacks built-in one.Mystic-Mirage commentedon May 10, 2019
I've tried to solve this in my PR #100
lucag commentedon Dec 27, 2022
Just ran into the same problem. Any progress on this?
@Mystic-Mirage's PR seems to be consistent with annotations currently in use, which employ stringified type names when a forward declaration is needed. So in the case of @dluciv's example, one would simply write
Another possible solution would be to use the
Selftype introduced by PEP 673, but that also does not work with the current implementation ofmultipledispatch.Mystic-Mirage commentedon Dec 27, 2022
There is another way to fix this by adding support for
from __future__ import annotationsintroduced in PEP 563Currently, it breaks
multipledispatchcompletely but looks promising.