Overloading methods in C API
tim.one at comcast.net
Sat Jan 18 16:27:23 CET 2003
> Is method/function overloading common in Python modules?
No. As Martin said, it's not *supported* in Python.
> Is it looked down upon?
It's more that it can't be spelled: there are no type declarations in
Python. You can write a function
that accepts any type of argument, but there's no way to say, via
declaration, that it only accepts a *particular* type of argument. So if
you want f(int) to do one thing and f(float) another, runtime code in the
body of f has to branch on type(x). People have also invented elaborate
registration schemes for more-or-less automating this kind of thing, but
it's unnatural in Python and such packages are rarely used. They don't get
away from runtime branching on type, they just hide it under additional
layers of obscurity <0.9 wink>.
The only kind of overloading naturally supported in Python is
single-dispatch OO-style (a single method name can be implemented in a
different way by each class that chooses to support a method of that name):
the meaning of x.meth() is whatever type(x) says "meth" means.
More information about the Python-list