[Python-3000] Use cases for type annotations? (WAS: Type parameterization)
Talin
talin at acm.org
Sat May 20 07:38:54 CEST 2006
Steven Bethard wrote:
>
> Which brings me to my comment about the current discussion. Can't we
> drop the syntax discussion for a while and have someone motivate it
> with some use-cases first? Sure, I can figure out what ``dict[str,
> str|int]`` means, but I still have no idea what you'd gain by
> declaring a parameter to have such a type. Should it add checks every
> time __getitem__ or __setitem__ is called?
>
> I think that if we can figure out what people would actually use type
> annotations for, I think it'll be much clearer what exactly needs
> syntactic support. At the moment, I can see a few simple uses that
> would only make things painful -- e.g. parameters getting declared as
> ints when any number type would work -- or that seem too
> computationally inefficient -- e.g. dict[str, str] would presumably
> have to add type-checks at every __getitem__ or __setitem__ call.
I'm less interested in type-checking than in type-inferencing, that is,
making logical deductions about the code based on types. Multi-dispatch
is one example of this.
Here's a list of use cases that I can think of:
1) Type checking
2) Dispatching based on the type of arguments.
3) Documentation scanners that can extract type information.
4) Static code analysis tools.
5) Implementation of mini-languages (algebraic solvers, expert systems,
etc.) within Python.
6) Using type information to optimize packet formats for RPC calls.
7) Method to declare functions that communicate with statically-typed
libraries or network protocols.
8) Optimized code generation for Python native-code compilers.
-- Talin
More information about the Python-3000
mailing list