[Python-ideas] Proposal: Use mypy syntax for function annotations
Paul Moore
p.f.moore at gmail.com
Wed Aug 20 15:28:55 CEST 2014
On 14 August 2014 00:30, Guido van Rossum <guido at python.org> wrote:
> We certainly *could* do that. However, I haven't seen sufficient other uses
> of annotations. If there is only one use for annotations (going forward),
> annotations would be unambiguous. If we allow different types of
> annotations, there would have to be a way to tell whether a particular
> annotation is intended as a type annotation or not. Currently mypy ignores
> all modules that don't import typing.py (using any form of import
> statement), and we could continue this convention. But it would mean that
> something like this would still require the typing import in order to be
> checked by mypy:
>
> import typing
>
> def gcd(int a, int b) -> int:
> <tralala>
Sorry, I'm slowly going through this thread, so my apologies if this
has been covered later, but it seems to me that projects (and in
particular libraries) that want to target 2.7 as well as 3.x will be
forced to avoid this feature. And avoid any dependencies that use it.
Specifically, the annotation syntax is purely Python 3.x, so without
some form of translation or import hook, 2.7 won't accept it. And
adding a dependency (even if it's only a very lightweight typing.py
plus a hook installed somewhere/somehow) for something that only has
value as part of a developer-level type check doesn't seem like a good
solution.
So, I'd like someone to explain (maybe by pointing me to relevant mypy
docs, I haven't investigated them yet) how I should modify my existing
code that supports 2.7 and 3.x so that it uses the new functionality
*without* extra runtime dependencies that only deliver build/test-time
benefits (that's the problem I always had with
setuptools/pkg_resources, and I'd not like to see it repeated here).
Paul
More information about the Python-ideas
mailing list