dropbox / pyannotate

Auto-generate PEP-484 annotations
Apache License 2.0
1.43k stars 59 forks source link

Compatibility issues with Python 3.5 because of typing stub #12

Closed jabdoa2 closed 6 years ago

jabdoa2 commented 6 years ago

On Ubuntu 16.04 LTS pyannotate breaks when using Python 3.5 because is ships with a limited typing stub. Upgrading typing via pip does not help since the built-in takes precedence (know issue).

pyannotate -w "mpf/assets/show.py"
Traceback (most recent call last):
  File "/usr/local/bin/pyannotate", line 7, in <module>
    from pyannotate_tools.annotations.__main__ import main
  File "/usr/local/lib/python3.5/dist-packages/pyannotate_tools/annotations/__main__.py", line 9, in <module>
    from pyannotate_tools.annotations.main import generate_annotations_json
  File "/usr/local/lib/python3.5/dist-packages/pyannotate_tools/annotations/main.py", line 9, in <module>
    from pyannotate_tools.annotations.infer import infer_annotation
  File "/usr/local/lib/python3.5/dist-packages/pyannotate_tools/annotations/infer.py", line 8, in <module>
    from pyannotate_tools.annotations.parse import parse_type_comment
  File "/usr/local/lib/python3.5/dist-packages/pyannotate_tools/annotations/parse.py", line 12, in <module>
    from typing import Any, List, Mapping, Set, Text, Tuple
ImportError: cannot import name 'Text'

Can this be fixed? Maybe "hide" the typing import behind an if True?

This works as a workaround: PYTHONPATH=/usr/local/lib/python3.5/dist-packages/ pyannotate

gvanrossum commented 6 years ago

Ideally you should upgrade to Python 3.5.2, which IIRC does have Text in typing.py.

Alternatively, Text is defined in typing_extensions, which you can install via pip install. Maybe you can submit a PR with a fix? (It's not easy for me to test since I don't have such an environment any more.)

gvanrossum commented 6 years ago

This should now be fixed as of #32. (There's no release for that yet, I'm waiting to accumulate more fixes.)

gvanrossum commented 6 years ago

Closing since it's fixed in master.