[Python-3000] Misc type annotation issues
Collin Winter
collinw at gmail.com
Sat May 20 18:19:48 CEST 2006
Some things I still have listed as "outstanding issues" for the annotations PEP:
1. You mentioned in one blog post [1] that you wanted to have 'any'
and 'nothing' types. Is this still something you want as built-ins, or
should it be left up to the annotation-interpreting libraries to
provide these?
2. Do you still want syntactic support for super/subtyping? In [1],
you mention using something like "T1 <= T2" to indicate that T1 is a
subtype of T2 and "T2 >= T1" to say T2 is a supertype of T1.
If you still want this syntax, what do these inequalities return? The
obvious answer is "a boolean", but you go on to use something like
"list[T <= Number]" to indicate a list of subtypes of Number. To me,
this latter example should be written "list[Number]", freeing <= and
>= on types to return booleans as expected.
However, since we're giving so much control to the
annotation-interpreting libraries, trying to define a useful and
consistent semantic for built-in super/subtyping inequalities would
run into the same problem as would a built-in typecheck() function.
Like typecheck(), it would be better to let the third-party libraries
provide their own issubtype() and issupertype() functions.
3. What will annotations on *varargs and **varkw look like? My own
suggestion is that
>>> def foo(a: <type>, *varargs: <type>, **varkw: <type>)
is fully equivalent to -- and is indeed coerced to --
>>> def foo(a: <type>, *varargs: list[<type>], **varkw: dict[str, <type>])
What did you have in mind?
Collin Winter
[1] - http://www.artima.com/weblogs/viewpost.jsp?thread=86641
More information about the Python-3000
mailing list