[Python-3000] Use cases for type annotations? (WAS: Type parameterization)

Steven Bethard steven.bethard at gmail.com
Sat May 20 22:43:00 CEST 2006


On 5/20/06, Guido van Rossum <guido at python.org> wrote:
> On 5/20/06, Steven Bethard <steven.bethard at gmail.com> wrote:
> > And the only use-cases I could extract are:
[snip]
> > * function overloading[1].  I think Philip J. Eby had some interesting
> > thoughts here, but in all the prototypes, dispatching was done on
> > concrete types.  Is there a way to do function overloading that
> > doesn't rule-out duck typing and is still reasonably efficient?
>
> 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
It does allow you to dispatch on other predicates, but in the current
prototype incarnation,  implies() is defined in terms of issubclass.
Of course, the nice thing about Phillip's approach is that you can
overload implies() so that, for example, you can use hasattr() like
you suggest above, but I haven't seen any examples yet where this was
actually done.

> > I guess, in general, my concerns about the use-cases I found were that:
> >
> > (1) there were very few real implementations of the ideas, and
>
> 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?

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?

> > Is it the intention that type annotations be used primarily to check
> > concrete types?
>
> To the contrary, that would be a big mistake.

Phew. ;-)  And thanks for all the clarifications.

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?

STeVe
-- 
Grammar am for people who can't think for myself.
        --- Bucky Katt, Get Fuzzy


More information about the Python-3000 mailing list