bintoro / overloading.py

Function overloading for Python 3
MIT License
112 stars 10 forks source link

Is there a way to override-overload a function? #2

Open wldhx opened 8 years ago

wldhx commented 8 years ago

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?

bintoro commented 8 years ago

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: