[Python-ideas] Trial balloon: adding variable type declarations in support of PEP 484
Steven D'Aprano
steve at pearwood.info
Fri Aug 5 22:09:33 EDT 2016
On Fri, Aug 05, 2016 at 11:03:55PM +0200, Sven R. Kunze wrote:
> Will arbitrary expressions work or only type declarations?
>
> a: <expression>
My understanding is that the Python interpreter will treat the part
after the colon as a no-op. So long as it is syntactically valid, it
will be ignored, and never evaluated at all.
# Okay
spam: fe + fi * fo - fum
# SyntaxError
spam: fe fi fo fum
But the type-checker (if any) should be expected to complain bitterly
about anything it doesn't understand, and rightly so. I think that this
form of variable annotation should be officially reserved for type
hints, and only type hints.
--
Steve
More information about the Python-ideas
mailing list