DEV Community

Discussion on: Overload Functions in Python

Collapse
 
dmitrypolo profile image
dmitrypolo

Not sure if you are aware of this, but the standard library already provides this functionality in the typing module. You can see the docs here

Collapse
 
arpit_bhayani profile image
Arpit Bhayani

I believe that the overload in the typing module is not how function overloading should be implemented. What it does is it helps us declare functions with the same name and different args but restricts us from invoking them.

Since we are not allowed to invoke an overload decorated function it becomes extremely painful to have just one function definition that handles all overloaded behavior and fill it with ifs and elses.

In this article, I tried to tackle this very situation where we could also invoke an @overload decorated function and thus eradicate the need of having one definition to cover everything.

Thanks.