I guess these two questions are related, so I'll post them together:
1.- Is it possible to put type hint in chained assignments?
These two attempts failed:
>>> def foo(a:int):
... b: int = c:int = a
File "<stdin>", line 2
b: int = c:int = a
^
SyntaxError: invalid syntax
>>> def foo(a:int):
... b = c:int = a
File "<stdin>", line 2
b = c:int = a
^
SyntaxError: invalid syntax
2.- Is it possible to put type hint in multiple assignments?
These were my attempts:
>>> from typing import Tuple
>>> def bar(a: Tuple[int]):
... b: int, c:int = a
File "<stdin>", line 2
b: int, c:int = a
^
SyntaxError: invalid syntax
>>> def bar(a: Tuple[int]):
... b, c:Tuple[int] = a
...
File "<stdin>", line 2
SyntaxError: only single target (not tuple) can be annotated
>>> def bar(a: Tuple[int]):
... b, c:int = a
...
File "<stdin>", line 2
SyntaxError: only single target (not tuple) can be annotated
I am aware that in both cases the type is inferred from the type hint of a, but I have a long variable list (in the __init__
of a class) and I want to be extra-explicit.
I am using Python 3.6.8.