[Python-ideas] Trial balloon: adding variable type declarations in support of PEP 484
Brendan Barnwell
brenbarn at brenbarn.net
Thu Aug 4 14:33:30 EDT 2016
On 2016-08-01 14:31, Guido van Rossum wrote:
> PEP 484 doesn't change Python's syntax. Therefore it has no good
> syntax to offer for declaring the type of variables, and instead you
> have to write e.g.
>
> a = 0 # type: float
> b = [] # type: List[int]
> c = None # type: Optional[str]
Let me ask a perhaps silly question. Reading a lot of subsequent
messages in this thread, it seems that the main intended use for all
this is external static type checkers. (Hence all the references to
thinking with "runtime hats" on.) Given this, what is the benefit of
making this change to Python syntax? If it's only going to be used by
static checker tools, is there any difference between having those tools
grab it from comments vs. from "real" syntax? This seems doubly
questionable if, for local variables, the type annotations are totally
unavailable at runtime (which I think is what was suggested). 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.
--
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no
path, and leave a trail."
--author unknown
More information about the Python-ideas
mailing list