3 ms·
The feature itself is not type hinting but simply a way to associate arbitrary Python object to essentially any other slot (variable, argument, return value, wh
by dfox 8y ago
The 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)