overloading.py
overloading.py copied to clipboard
Is there a way to override-overload a function?
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?
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
@overloadedand then use@overloadthereafter 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.