mypy-tools icon indicating copy to clipboard operation
mypy-tools copied to clipboard

Add Python 3 support for mypy_server.py

Open emcek opened this issue 7 years ago • 4 comments

probably not mypy-tools related but can't fix it:

$ python3.6 /usr/local/bin/mypy_server.py 
Traceback (most recent call last):
  File "/usr/local/bin/mypy_server.py", line 3, in <module>
    from mypytools.server import mypy_server
  File "/usr/local/lib/python3.6/dist-packages/mypytools/server/mypy_server.py", line 20, in <module>
    from mypytools.server.mypy_http_request_handler import HttpServerThread
  File "/usr/local/lib/python3.6/dist-packages/mypytools/server/mypy_http_request_handler.py", line 6, in <module>
    from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
ModuleNotFoundError: No module named 'BaseHTTPServer'

add PYTHONPATH

$ export PYTHONPATH=/usr/local/lib/python3.6/dist-packages/

different problem

$ python3.6 /usr/local/bin/mypy_server.py
Traceback (most recent call last):
  File "/usr/local/bin/mypy_server.py", line 2, in <module>
    import click
  File "/usr/local/lib/python3.6/dist-packages/click/__init__.py", line 18, in <module>
    from .core import Context, BaseCommand, Command, MultiCommand, Group, \
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 8, in <module>
    from .types import convert_type, IntRange, BOOL
  File "/usr/local/lib/python3.6/dist-packages/click/types.py", line 4, in <module>
    from ._compat import open_stream, text_type, filename_to_ui, \
  File "/usr/local/lib/python3.6/dist-packages/click/_compat.py", line 1, in <module>
    import re
  File "/usr/lib/python3.6/re.py", line 142, in <module>
    class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'

emcek avatar Dec 04 '17 14:12 emcek

Ah, the first error is because Python 3 doesn't have BaseHTTPServer any more. mypy_server.py doesn't quite support Python 3 yet. Not sure about the second error, but from some brief googling it looks like it might be caused by the fact you set your PYTHONPATH manually.

mhahnenberg avatar Dec 04 '17 18:12 mhahnenberg

thx... it helped a bit... looks like python3 type hinting isn't supported

$ mypy_server.py
Initializing mypy server...Traceback (most recent call last):
  File "/usr/local/bin/mypy_server.py", line 13, in <module>
    main()
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/bin/mypy_server.py", line 10, in main
    mypy_server.run_server(compact=compact)
  File "/usr/local/lib/python2.7/dist-packages/mypytools/server/mypy_server.py", line 55, in run_server
    g = build_dependency_graph(src_dirs, silence=False)
  File "/usr/local/lib/python2.7/dist-packages/mypytools/server/mypy_server.py", line 36, in build_dependency_graph
    g.parsePathname(d)
  File "/usr/local/lib/python2.7/dist-packages/findimports.py", line 427, in parsePathname
    self.parseFile(os.path.join(root, fn))
  File "/usr/local/lib/python2.7/dist-packages/findimports.py", line 454, in parseFile
    module.imported_names = find_imports(filename)
  File "/usr/local/lib/python2.7/dist-packages/findimports.py", line 320, in find_imports
    root = ast.parse(f.read(), filename)
  File "/usr/lib/python2.7/ast.py", line 37, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "/home/emc/pycharm/cloud_tools/crtd/crt_dispatcher/__init__.py", line 36
    def __init__(self) -> None:
                       ^
SyntaxError: invalid syntax

emcek avatar Dec 06 '17 09:12 emcek

I think what's happening here is that the ast module in Python 2.7 doesn't know how to parse Python 3 code. Python 3 support for mypy_server.py (both for running and for parsing) are on the roadmap! The other tools in the package should support Python 3 however.

mhahnenberg avatar Dec 06 '17 15:12 mhahnenberg

nice!

emcek avatar Dec 06 '17 15:12 emcek