[Python-3000] Use cases for type annotations? (WAS: Type parameterization)
Guido van Rossum
guido at python.org
Sun May 21 01:23:37 CEST 2006
On 5/20/06, Steven Bethard <steven.bethard at gmail.com> wrote:
> On 5/20/06, Guido van Rossum <guido at python.org> wrote:
> > You may have read my prototypes, which dispatch on concrete types.
> > Phillip lets you dispatch on predicates like hasattr(x, 'append').
>
> I assume you mean this one:
> http://svn.python.org/projects/sandbox/trunk/Overload3K
No, I meant his Dispatch thing. It's somewhere on the PEAK website and
has been discussed here before.
> > Collin Winters is pretty real, and I believe one other person (Tony
> > Lownds?) has another.
>
> I wandered around
> http://oakwinter.com/code/typecheck/
> but couldn't find any discussion about the implications of, say,
> requring the type ``{str:Number}`` (which I assume is basically
> equivalent to the dict[str, Number] in this discussion). Does that
> mean that every access to the dict is checked?
That's for Collin to answer.
> I do like the idea of the TypeClass object, which basically infers an
> interface. But I'd really like someone to discuss the performance
> implications somewhere. Maybe it is and I just couldn't find it?
I expect performance is going to kill the wrapper approach, which is
why I'm at best lukewarm towards it.
> I guess in the end, I'm still a little confused at why we're having a
> syntax discussion now. If type annotations are just an extra
> expression in a function definition, why does Python core care about
> what syntax a system like Phillip's or Collin's chooses? That is,
> isn't the ``dict[str, int]`` or ``{str: int}`` syntax decision just a
> decision for the ``typecheck`` or ``overloading`` module, and not for
> Python in general?
It is indeed up to the framework, not up to Python.
However we might as well give some guidance, and e.g. parameterized
types a la list[int] (or ImmutableSequence[Number]) is my proposal
*if* I were asked to design a sub-language for expression type
constraints.
Also, if we want IDEs to use this (e.g. for name completion) we should
have agreement on the syntax.
But if someone wants to use the annotation slot as a mini-docstring
for parameters, or to add a validation function for a web framework,
or whatever, they should be free to do so (as long as they don't care
about the IDE support, which so far is just a dream anyway).
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list