Skip to content

mypy crashes while trying to process appdirs source file #5121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pradyunsg opened this issue May 30, 2018 · 5 comments
Closed

mypy crashes while trying to process appdirs source file #5121

pradyunsg opened this issue May 30, 2018 · 5 comments

Comments

@pradyunsg
Copy link
Member

Version: 0.600 and current master 0447473
Flags used: --ignore-missing-imports

Minimum Reproduction Case

$ # in a fresh virtualenv
$ pip install appdirs==1.4.3
[...]
$ pip install https://github.com/python/mypy/archive/master.zip
[...]
$ mypy $(python -c "import appdirs; print(appdirs.__file__)") --ignore-missing-imports --show-traceback
/Users/pradyunsg/[snip]/lib/python3.6/site-packages/appdirs.py: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.610+dev
Traceback (most recent call last):
  File "/Users/pradyunsg/[snip]/bin/mypy", line 11, in <module>
    sys.exit(console_entry())
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry
    main(None)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/main.py", line 91, in main
    res = type_check_only(sources, bin_dir, options, flush_errors, fscache)  # noqa
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/main.py", line 148, in type_check_only
    fscache=fscache)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/build.py", line 185, in build
    flush_errors, fscache)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/build.py", line 285, in _build
    graph = dispatch(sources, manager)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/build.py", line 2398, in dispatch
    process_graph(graph, manager)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/build.py", line 2691, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/build.py", line 2801, in process_stale_scc
    graph[id].semantic_analysis()
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/build.py", line 2009, in semantic_analysis
    self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options, patches)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/build.py", line 1818, in wrap_context
    yield
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/build.py", line 2009, in semantic_analysis
    self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options, patches)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/semanal.py", line 291, in visit_file
    v.type = self.anal_type(v.type)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/semanal.py", line 1578, in anal_type
    typ = t.accept(a)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/types.py", line 203, in accept
    return visitor.visit_unbound_type(self)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/typeanal.py", line 178, in visit_unbound_type
    typ = self.visit_unbound_type_nonoptional(t)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/typeanal.py", line 186, in visit_unbound_type_nonoptional
    sym = self.lookup(t.name, t, suppress_errors=self.third_pass)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/semanal.py", line 3058, in lookup_qualified
    n = self.lookup(parts[0], ctx, suppress_errors=suppress_errors)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/semanal.py", line 3038, in lookup
    self.name_not_defined(name, ctx)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/semanal.py", line 3246, in name_not_defined
    self.fail(message, ctx)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/semanal.py", line 3281, in fail
    self.errors.report(ctx.get_line(), ctx.get_column(), msg, blocker=blocker)
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/errors.py", line 260, in report
    target=self.current_target())
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/errors.py", line 208, in current_target
    return self.scope.current_target()
  File "/Users/pradyunsg/[snip]/lib/python3.6/site-packages/mypy/scope.py", line 30, in current_target
    assert self.module
AssertionError:
/Users/pradyunsg/[snip]/lib/python3.6/site-packages/appdirs.py: : note: use --pdb to drop into pdb

Context

appdirs is a vendored package in pip, errors from which are ignored using ignore_errors=True in a configuration file. The working idea is to use mypy to annotate pip's own sources while not touching the vendored files.

@pradyunsg pradyunsg changed the title mypy crashes while trying to process an ignored file mypy crashes while trying to process appdirs source file May 30, 2018
@pradyunsg
Copy link
Member Author

Interesting...

Deleting all the contents of that file and running mypy again, results in the same error.
Dropping the --ignore-missing-imports flag gives me (with an empty file):

lib/python3.6/site-packages/appdirs.py:1: error: Cannot find 'builtins' module. Typeshed appears broken!

@gvanrossum
Copy link
Member

I presume that passing the absolute pathname for appdirs somehow adds site-packages to mypy's search path, which is known to be a bad idea. See the warnings in the docs: http://mypy.readthedocs.io/en/latest/basics.html (scroll to bottom).

@pradyunsg
Copy link
Member Author

This occurs even when it's not in site-packages:

$ pwd
/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0
$ mv $(python -c "import appdirs; print(appdirs.__file__)") .
$ mypy ./appdirs.py --ignore-missing-imports --show-traceback
./appdirs.py: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.610+dev
Traceback (most recent call last):
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/bin/mypy", line 11, in <module>
    sys.exit(console_entry())
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry
    main(None)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/main.py", line 91, in main
    res = type_check_only(sources, bin_dir, options, flush_errors, fscache)  # noqa
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/main.py", line 148, in type_check_only
    fscache=fscache)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/build.py", line 185, in build
    flush_errors, fscache)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/build.py", line 285, in _build
    graph = dispatch(sources, manager)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/build.py", line 2398, in dispatch
    process_graph(graph, manager)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/build.py", line 2691, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/build.py", line 2801, in process_stale_scc
    graph[id].semantic_analysis()
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/build.py", line 2009, in semantic_analysis
    self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options, patches)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/build.py", line 1818, in wrap_context
    yield
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/build.py", line 2009, in semantic_analysis
    self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options, patches)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/semanal.py", line 291, in visit_file
    v.type = self.anal_type(v.type)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/semanal.py", line 1578, in anal_type
    typ = t.accept(a)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/types.py", line 203, in accept
    return visitor.visit_unbound_type(self)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/typeanal.py", line 178, in visit_unbound_type
    typ = self.visit_unbound_type_nonoptional(t)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/typeanal.py", line 186, in visit_unbound_type_nonoptional
    sym = self.lookup(t.name, t, suppress_errors=self.third_pass)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/semanal.py", line 3058, in lookup_qualified
    n = self.lookup(parts[0], ctx, suppress_errors=suppress_errors)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/semanal.py", line 3038, in lookup
    self.name_not_defined(name, ctx)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/semanal.py", line 3246, in name_not_defined
    self.fail(message, ctx)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/semanal.py", line 3281, in fail
    self.errors.report(ctx.get_line(), ctx.get_column(), msg, blocker=blocker)
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/errors.py", line 260, in report
    target=self.current_target())
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/errors.py", line 208, in current_target
    return self.scope.current_target()
  File "/Users/pradyunsg/.venvwrap/venvs/tmp-da2b6c4ef2234c0/lib/python3.6/site-packages/mypy/scope.py", line 30, in current_target
    assert self.module
AssertionError:
./appdirs.py: : note: use --pdb to drop into pdb

@ilevkivskyi
Copy link
Member

This occurs even when it's not in site-packages:

Probably because your install is broken, as mypy says

error: Cannot find 'builtins' module. Typeshed appears broken!

Have you tried installing as recommended instead if using .zip?

@pradyunsg
Copy link
Member Author

Have you tried installing as recommended instead if using .zip?

I didn't realize that mypy had special instructions for installation from source.

It seems to be that the zip doesn't contain typeshed submodule. Installing by cloning with the submodule worked. Thanks for the pointer @ilevkivskyi! Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants