overloading.py icon indicating copy to clipboard operation
overloading.py copied to clipboard

Is there a way to override-overload a function?

Open wldhx opened this issue 9 years ago • 1 comments

That's mostly relevant for interactive usecases such as REPL or a Jupyter Notebook.

Suppose I have a function

def f(a: int):
    return a

and at some point (in an interactive session, with ^ already declared), want to change it, to, for i.,

def f(a: int):
    return a * 2

This would fail as of overloading==0.5.0 with OverloadingError: Failed to overload function 'f': non-unique signature. Can I somehow force an override?

wldhx avatar Jul 14 '16 16:07 wldhx

Overriding a single implementation is not yet possible. However, you can redeclare f in its entirety when using the @overloaded / @overloads(...) syntax. Simply use @overloaded on the first variant, and a new dispatcher is created that starts out with a clean slate.

Let's keep the issue open because there are ways in which the current situation could be improved:

  • It would be nice to be able to reset the function via @overloaded and then use @overload thereafter instead of @overloads(...).
  • Aside from REPL, there's another obvious use case for overriding a single implementation: a subclass might want to override a signature inherited from the superclass.

bintoro avatar Jul 28 '16 18:07 bintoro