[Python-3000] Type parameterization (was: Re: Type annotations: annotating generators)
Collin Winter
collinw at gmail.com
Fri May 19 22:04:09 CEST 2006
On 5/19/06, Jim Jewett <jimjjewett at gmail.com> wrote:
> On 5/19/06, Collin Winter <collinw at gmail.com> wrote:
> > ... what do you think of ... having bracket-based parameterization be
> > redirected a call to some double-underscore method
>
> It already is -- to __getitem__.
>
> Having it go to something else just because you're in a function
> definition is asking for trouble. What should happen in the following
> case?
>
> b=dict(strict=check1, lenient=check2, normal=check3)
>
> def foo(a:b["normal"]): pass
>
> Should it really look for some special method on b (or b's type) just
> because it is in a signature context? Today, the annotation
> expression would evaluate to check2, and I'm not looking forward to
> figuring out all the corner cases on when that wouldn't happen.
dict(normal=check3)["normal"] is not the same as dict["normal"] --
Guido and I have been discussing the latter. When I said "redirected",
I meant that dict's metaclass would catch the __getitem__ call and
then invoke dict.__parameterize__() appropriately.
Collin Winter
More information about the Python-3000
mailing list