4 ms·
Does python 3.6 support type hinting? This reminds me of php 7+ with scalor types, and return types now. Didn't think python supported this.
by krob 8y ago
Does python 3.6 support type hinting? This reminds me of php 7+ with scalor types, and return types now. Didn't think python supported this.
- jakereps 8y agoYes, Python introduced static type hinting in version 3.5 https://www.python.org/dev/peps/pep-0484/ https://www.python.org/dev/peps/pep-0484/
- ubernostrum 8y agoPython introduced the 'typing' module in the standard library in 3.5, and declared that henceforth the annotation syntax was for type hints. Python introduced the annotation syntax (for everything except variables/attributes) in 3.0. The annotation syntax for variables/attributes was introduced in 3.6.
- dfox 8y agoThe feature itself is not type hinting but simply a way to associate arbitrary Python object to essentially any other slot (variable, argument, return value, whatever...) that can hold reference to Python object. The interpreter is supposed to not care about values of such annotations, which makes it a powerful syntactic construct that can be used and abused for various purposes. My two evening project was PyCLOS, which (ab)uses these annotations to provide CLOS style multimethods in python (it is sadly CPython dependent, because the Python side relies on CPython implementation details and while the C extension is not mandatory it is essentially required to get reasonable performance, with somewhat surprising observation that PyCLOS dispatch is measuringly faster than normal attribute access in most cases)