Python's idiom for function overloads

Jacek Generowicz jacek.generowicz at cern.ch
Tue Feb 1 05:08:25 EST 2005


Philippe Fremy <phil at freehackers.org> writes:

> 	Hi Frans,
> 
> > Since Python doesn't have static typing, how is the same result as
> > traditional function overloads results in acheived?
> 
> 
> With dynamic typing obviously. :-)
> 
> You can not reproduce the C++ overload idiom

Of course you can. Use a multimethod of some sort.

The canonical answer to the OQ, of course, includes things like
"Consider whether you really want/need to do this" and "duck typing".

Frequently, in Python, code which checks for types, rather than
checking for features, ends up being excessively restrictive and
insufficiently general.



More information about the Python-list mailing list