other python ideas

Michael Hudson mwh21 at cam.ac.uk
Tue May 23 11:02:48 EDT 2000


"Richard Brodie" <R.Brodie at rl.ac.uk> writes:

> "Thomas Thiele" <thiele at muc.das-werk.de> wrote in message news:392A7F84.A3D5F34A at muc.das-werk.de...
> > function overloading is a goog idea. It's really the only thing I miss in
> > python.
> > But then it must be possible to check different data-types (like in C++).
> >
> > def foo(   (int)a  ):
> >     print a, "is a int"
> >
> > def foo(   (float)a  ):
> >     print a, " is a float"
> 
> It's not so hard to write a dispatch function if that's what you really want:
> 
> from types import *
> 
> def overloaded(t):
>     dispatch = { IntType: intFunc, FloatType: floatFunc}
>     if dispatch.has_key(type(t)) :
>         dispatch[type(t)](t)
>     else :
>         defaultFunc(t)

But you want thing like this to work:

class A:
   pass
class B(A):
   pass
class C(B):
   pass

def foo(x:A):
    print "A"
def foo(x:B):
    print "B"

foo(C()) => "B"

I'd really really like to see this in Python, but it's something of a
sea change, and adds significant complexity to the language.

Cheers,
M.

-- 
  Academic politics is the most vicious and bitter form of politics,
  because the stakes are so low.                      -- Wallace Sayre



More information about the Python-list mailing list