4 ms·
Since Python 3.5 (3 years ago) type hints are part of the core syntax. Don't need to put them in comments. https://www.python.org/dev/peps/pep-0484/#type-defin
by jononor 9y ago
Since Python 3.5 (3 years ago) type hints are part of the core syntax. Don't need to put them in comments.
https://www.python.org/dev/peps/pep-0484/#type-definition-syntax https://www.python.org/dev/peps/pep-0484/#type-definition-sy...
- tobltobs 9y ago> a_list = [] # type: List[T] How do you do that with out a comment?
- Osmium 9y ago> a_list: List[T] = []
- umanwizard 9y agoa_list: List[T] = []
- Chickenosaurus 9y agofrom typing import List a_list: List[T] = [] Visit https://docs.python.org/3/library/typing.html https://docs.python.org/3/library/typing.html for more information.
- oblio 9y agoThey badly need to update the docs, then. Almost everything I see on that page does this: vec = [] # type: Vector[float] vec = [] # type: Iterable[Tuple[float, float]] a = MyClass() # type: MyClass[int] x = Foo() # type: Foo[int]
- icegreentea2 9y agoUgh that's because PEP 484 (which introduced 'proper' type hints) only introduced it for parameters and return types and implemented in Python 3.5. Type hinting bare variables was introduced with PEP 526 and implemented in Python 3.6. While I really like the concept of PEPs, and I think keeping original (like as they were written) PEPs around are the right thing to do, I do wish sometimes that Python did a better job at incorporating changes from PEPs into the core documentation once implemented.