Python Method Overloading
Gourab Datta
Data Engineering Lead | Consulting | Data Analytics | Apache Spark | Big Data | Databricks Apache Spark Certified | Big Data Lead | Azure
You might be able to get the code snippet and explanation on the internet easily, but objective of the article is information sharing.
In ideal world of python, it does not support method overloading . it supports method overriding but certainly not method overloading.
In below example we can see that it throws error due to wrong method signature though show() signature is present but it is not able to access due to method overriding .
?
But there might be requirement where developers need same function name to maintain code standards, but calculation would be different based on requirements. How exactly that can be solved in python. For that python has 3rd party tool called multipledispatch python library.
It comes handy during this scenarios and life saver for developers.
Please find example below:
In above example using dispatch decorator we are passing param type so that python interpreter will be able to understand which method to invoke based on method signature.
Thanks
Gourab