[Python-ideas] Improving the expressivity of function annotations

Michael Foord fuzzyman at gmail.com
Mon Apr 4 20:47:09 CEST 2011


On 4 April 2011 19:22, Terry Reedy <tjreedy at udel.edu> wrote:

> I am not sure, what, if anything, we should do to make annotations more
> useful. I think it is too soon to do anything *official* yet.
>
> On 4/4/2011 4:31 AM, Masklinn wrote:
>
>  type parameters (generics)
>>
>
> I do not know what 'generics' means (and neither, that I could find, does
> Wikipedia) but type-parameter is not obvious as a synonym ;-).
>
>

http://en.wikipedia.org/wiki/Generic_programming

It's a standard term for languages like C# and Java, but if you don't use
these languages there is no reason you should know it. Generics is a
solution (hack - but still an elegant hack) that allows you to write
"generic" containers and functions that can work with any types whilst still
being type safe. For example, in C# you might have a list type that can
contain elements of a specific type. The list can be written once using
generics, then can be used with any type - with the specific type being
specified (the type parameter) at compile time where you use it. E.g.

    var list_of_ints = new List[int]();

HTH,

Michael Foord


>
>  ``type`` instances (with e.g. ``list[int]`` yielding a list with some
>> kind of ``generics`` attribute),
>>
>
> That sounds a lot like array with a typecode. You can use a dict subclass
> or UserDict to get a mapping with restricted keys and values, with bad
> inputs ignored, coerced, or error raising as you please. Ditto for lists.
>
>
>  Sum = (A | B | C)
>>
> > assert issubclass(A, Sum)
>
> That appears to be exactly the same as
>
> Sum = (A,B,C)
> assert issubclass(A, Sum)
>
> Sum2=Sum|D # same as
> Sum2=Sum+(D,)
>
> so the purpose of the duplication is not obvious.
>
>
>  Anyway this is where "structural types" come in: defining a type not
>> by its name but by its shape (a set of methods and properties, and
>> their signatures).
>>
>
> When it comes to tracebacks, multiple unbound functions with duplicate
> f.__name__ == '<lambda>' attributes are inferior to functions with, in a
> particular context, unique names. I would feel the same about multiple
> stypes with .__name__ == '<stype>'.
>
> --
> Terry Jan Reedy
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



-- 

http://www.voidspace.org.uk/

May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110404/d7ba5da5/attachment.html>


More information about the Python-ideas mailing list