Overloading methods in C API

Carl Banks imbosol at vt.edu
Sat Jan 18 16:24:15 EST 2003


Grant Edwards wrote:
> In article <Xns9307CD595EDCBrcamesz at amesz.demon.nl>, Robert Amesz wrote:
>> Grant Edwards wrote:
>> 
>>>> Is method/function overloading common in Python modules?
>>> 
>>> No.  It's isn't supported.  The language does not allow it. 
>>> Therefore, it is not common.
>> 
>> It's not that the language doesn't allow it, it's just that dynamic 
>> typing makes it impossible to decide beforehand what methods/functions 
>> would be called.
> 
> The language doesn't allow one to declare the types of function/method
> parameters.  Therefore function/method overloading is not possible.  In my
> mind, that can be summarized as "the language doesn't allow it."


His point is that you can write a function that dispatches on type
manually, like this:

    def fn(x):
        if type(x) == type(1):
            ...
        elif type(x) == type([]):
            ...


I would call that an overloaded function, even if it isn't technically
an Overloaded Function (tm).  


-- 
CARL BANKS




More information about the Python-list mailing list