[Python-ideas] Simple class initialization
Steven D'Aprano
steve at pearwood.info
Mon Apr 18 02:50:08 CEST 2011
Greg Ewing wrote:
> Steven D'Aprano wrote:
>
>> That's not a bug, that's a feature.
>>
>> It's been stated many times by Guido that it's far too early to
>> standardize on a single meaning for annotations.
>
> I think it's a rather *strange* feature.
>
> Imagine what would happen if someone other than Guido
> proposed a syntax extension with no defined semantics
> and no use cases. I don't think it would be very well
> received!
The benefits of being BDFL :)
But seriously, check the PEP: it's not written by Guido, and this
feature is not driven by whim.
http://www.python.org/dev/peps/pep-3107/
Annotations have at least one good use-case, and the semantics are
perfectly defined: annotations are arbitrary expressions, and they get
stored in the function object in a known place. What you do with those
annotations is up to you. That's no different from other general
processes in Python, like name binding, class attributes, and function
calling, which have open semantics.
("Okay, I've created a variable. What do I do with it now?" That's
entirely up to you, Python won't tell you what to do next.)
The only difference is that those other processes are so well-known and
have existed in some cases since the dawn of time (Fortran), and so we
take them for granted. Annotations in the Python sense are new, and
nobody knows what to do with them yet (except for the oh-so-predictable
idea of type testing -- boring!).
I think its a brave and innovative move. If it's not successful, that
says more about the conservativeness of Python programmers than the
usefulness of the feature. I bet Perl coders would have found some way
to make their code even more incomprehensible with it by now *grin*
More here on type checking in Python here:
http://lambda-the-ultimate.org/node/1519
In particular note the links to Guido's essays thinking aloud, which
eventually lead to annotations.
--
Steven
More information about the Python-ideas
mailing list