Metaclass with name overloading.

Ville Vainio ville at spammers.com
Mon Sep 27 14:54:58 EDT 2004


>>>>> "Alex" == Alex Martelli <aleaxit at yahoo.com> writes:

    Alex> For overload purposes, you might have the decorator actually
    Alex> take as arguments some _types_ and record them so that the
    Alex> metaclass can arrange for the dispatching based on
    Alex> actual-argument types...

I believe several implementations of generic functions/multimethods in
Python exist already; Quick googling brings up 

http://mail.python.org/pipermail/python-dev/2004-April/043902.html

def generic(*type_signature):
     """
     A decorator-generator that can be used to incrementally construct
     a generic function that delegates to individual functions based on
     the type signature of the arguments.  For example, the following
     code defines a generic function that uses two different actual
     functions, depending on whether its argument is a string or an
     int:

         >>> def f(x) [generic(int)]:
         ...     print x, 'is an int'
         >>> def f(x) [generic(str)]:
         ...     print x, 'is a string'


    Alex> If you bletch at having to decorate each overloaded version
    Alex> with '@overloaded', consider C# basically requires that
    Alex> "just BECAUSE", without even having a good excuse such as
    Alex> "we need to do it that way due to Python's semantics"...;-)

I think it's "override" in C#, and stands for overriding a method in base class:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfOverridePG.asp

-- 
Ville Vainio   http://tinyurl.com/2prnb



More information about the Python-list mailing list