[Python-ideas] Trial balloon: adding variable type declarations in support of PEP 484
Nick Coghlan
ncoghlan at gmail.com
Tue Aug 2 07:10:45 EDT 2016
On 2 August 2016 at 17:54, Paul Moore <p.f.moore at gmail.com> wrote:
> So in my view, allowing annotations on unpacking syntax is going to
> cause a *lot* of confusion, and I'd strongly argue for only allowing
> type annotations on single variables:
>
> VAR [: TYPE] [= INITIAL_VALUE]
>
> For multiple variables, just use multiple lines:
>
> a: int
> b: str = x
>
> or
>
> a: int
> b: str
> a, b = x
>
> depending on your intention.
>
> From what Guido says, the main use case is class variables, where
> complicated initialisations are extremely rare, so this shouldn't be a
> problem in practice.
+1 from me for this view: only allow syntactic annotation of single
names without parentheses. That one rule eliminates all the cases
where unpacking assignment and parameter assignment do starkly
different things.
*However*, even with that restriction, unambiguously annotated
unpacking could still be supported via:
(a, b) : Tuple[int, str] = x
(a, b, *c) : Tuple[int, int, Tuple[int]] = y
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list