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

Guido van Rossum guido at python.org
Wed Aug 3 19:53:55 EDT 2016


On Wed, Aug 3, 2016 at 3:02 PM, Pavol Lisy <pavol.lisy at gmail.com> wrote:
> If I understand this proposal then we probably need to consider this too:
>
> if something:
>   a: float
> else:
>   a: str
>
> a = 'what would static type-checker do here?'

The beauty of it is that that's entirely up to the static checker. In
mypy this would probably be an error. But at runtime we can make this
totally well-defined.

> del a
> a: int = 0

Ditto.

> def fnc():
>   global a: list

I'm not proposing to add such syntax, and the right place for the type
of a would be at the global level, not on the `global` syatement.

> a = 7
> fnc()
> a = [1, 2, 3]  # and this could be interesting for static type-checker too

Indeed, but that's not what we're debating here.

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-ideas mailing list