[Python-ideas] Improving the expressivity of function annotations

Terry Reedy tjreedy at udel.edu
Mon Apr 4 20:22:08 CEST 2011


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 ;-).

> ``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




More information about the Python-ideas mailing list