[Python-ideas] Trial balloon: adding variable type declarations in support of PEP 484
Guido van Rossum
gvanrossum at gmail.com
Thu Aug 4 12:15:02 EDT 2016
On Thu, Aug 4, 2016 at 8:40 AM, Alexander Belopolsky
<alexander.belopolsky at gmail.com> wrote:
> On Thu, Aug 4, 2016 at 11:22 AM, Guido van Rossum <gvanrossum at gmail.com> wrote:
>> However the presence of a local declaration like 'a: int' would create a
>> local slot for 'a' as if it were assigned to somewhere in the function.
>
> Does this mean that the following code will raise a NameError?
>
> a = None
> def f():
> a: int
> a
It will do exactly the same as
a = None
def f():
if False: a = ...
a
This raises UnboundLocalError (a subclass of NameError).
> (FWIW, I like the <var>: <type> notation more than any alternative
> proposed so far.)
Me too. :-)
--
--Guido van Rossum (python.org/~guido)
More information about the Python-ideas
mailing list