On Aug 20, 2014, at 10:11 AM, Brett Cannon
wrote: On Wed Aug 20 2014 at 9:29:34 AM Paul Moore
mailto:p.f.moore@gmail.com> wrote: On 14 August 2014 00:30, Guido van Rossum mailto:guido@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).
I suspect the answer is "you don't". Just like everything else that is syntactically exclusive to Python 3, it's a perk you get with Python 3-only code that you simply can't get if you want to maintain backwards-compatibility.
mypy does have a codec that will ignore annotations on 2.x. But other than that the answer is you don’t. --- Donald Stufft PGP: 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA