[Python-ideas] Trial balloon: adding variable type declarations in support of PEP 484

Brett Cannon brett at python.org
Fri Aug 5 12:17:20 EDT 2016


On Thu, 4 Aug 2016 at 12:20 Brendan Barnwell <brenbarn at brenbarn.net> wrote:

> On 2016-08-04 12:09, Alexander Belopolsky wrote:
>  > On Thu, Aug 4, 2016 at 2:33 PM, Brendan Barnwell
> <brenbarn at brenbarn.net> wrote:
>  >> It seems odd to have Python syntax that not only doesn't do
> anything, but
>  >> can't even be made to do anything by the program itself when it runs.
>  >
>  > Why do you find this odd?  Python already has #-comment syntax with
>  > exactly the property you complain about.  Think of local variable
>  > annotation as a structured comment syntax.
>
>         Exactly.  But the existing comment annotations (# type: float)
> already
> are structured comment syntax, so what does this new one add?  (Note we
> already have at least one parallel --- although it is much more limited
> in scope --- namely encoding declarations, which are also done within
> existing comment syntax, rather than having their own "real" syntax.)
>

[I'm going to give an explanation one shot, then I will leave the topic
alone as explaining the "why" definitely has the possibility of dragging on]

You're right this could be viewed as syntactic sugar, but then again so is
multiplication for integers as a short-hand for addition or the fact we
even have infix operators which translate to method calls on objects. In
all cases, the syntax is meant to either make people's lives easier to to
promote their use.

In this instance it both makes people's lives easier and promotes use. By
making it syntax it becomes easier to use as the compiler can now detect
when the information is improperly typed. And by making it syntax, not only
does it make sure there's a strong standard but lets people know that this
isn't some little feature but in fact is being promoted by the Python
language itself. There's also the disconnect of having type annotations on
function parameters but completely missing the OOP aspect of attributes  on
objects which leaves a gaping hole in terms of syntactic support for type
hints.

Hopefully that all makes sense as to why Guido has brought this up.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160805/b54df045/attachment.html>


More information about the Python-ideas mailing list