Skip to content

Exception while typechecking: KeyError: 'typing' #7412

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
corydolphin opened this issue Aug 29, 2019 · 3 comments
Closed

Exception while typechecking: KeyError: 'typing' #7412

corydolphin opened this issue Aug 29, 2019 · 3 comments

Comments

@corydolphin
Copy link

corydolphin commented Aug 29, 2019

Hello,

First, thank you all for your work on MyPy, adding static typing to Python is a huge boon.

MyPy is hitting an exception while typechecking our project, both with version 0.720 and with master 0.730+dev.8954045912e8d7f00af5d7d6289085dd8eb8c64a on Python 3.6.5

The minimal test case which triggers the exception is:

import contextlib


@contextlib.contextmanager
def do_nothing(*args, **kwargs):
    yield

When evaluated with a config file which contains follow_imports_for_stubs = True, as well as passing --follow-imports=skip in the commandline. Are these two incompatible? Their names almost suggest as much.

E.g.

[mypy]
follow_imports_for_stubs = True
python -m mypy --show-traceback --follow-imports=skip --config-file=example.cfg example.py
example.py:4: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.730+dev.8954045912e8d7f00af5d7d6289085dd8eb8c64a
Traceback (most recent call last):
  File "/var/lib/conda/envs/py35/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/var/lib/conda/envs/py35/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/__main__.py", line 12, in <module>
    main(None, sys.stdout, sys.stderr)
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/main.py", line 83, in main
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/build.py", line 163, in build
    result = _build(sources, options, alt_lib_path, flush_errors, fscache, stdout, stderr)
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/build.py", line 225, in _build
    graph = dispatch(sources, manager, stdout)
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/build.py", line 2562, in dispatch
    process_graph(graph, manager)
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/build.py", line 2871, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/build.py", line 2970, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/build.py", line 2066, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/checker.py", line 291, in check_first_pass
    self.accept(d)
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/checker.py", line 402, in accept
    stmt.accept(self)
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/nodes.py", line 756, in accept
    return visitor.visit_decorator(self)
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/checker.py", line 3294, in visit_decorator
    self.check_func_item(e.func, name=e.func.name())
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/checker.py", line 788, in check_func_item
    self.check_func_def(defn, typ, name)
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/checker.py", line 862, in check_func_def
    if not self.is_generator_return_type(typ.ret_type, defn.is_coroutine):
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/checker.py", line 611, in is_generator_return_type
    gt = self.named_generic_type('typing.Generator', [any_type, any_type, any_type])
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/checker.py", line 3843, in named_generic_type
    info = self.lookup_typeinfo(name)
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/checker.py", line 3849, in lookup_typeinfo
    sym = self.lookup_qualified(fullname)
  File "/var/lib/conda/envs/py35/lib/python3.6/site-packages/mypy/checker.py", line 3897, in lookup_qualified
    n = self.modules[parts[0]]
KeyError: 'typing'
example.py:4: : note: use --pdb to drop into pdb
@JukkaL
Copy link
Collaborator

JukkaL commented Aug 30, 2019

Here is a smaller example that will crash:

def f():
    yield

It looks like follow_imports_for_stubs = True and --follow-imports=skip don't work together at the moment. They cause the stub for typing to be skipped, which will break almost everything. I don't see why they couldn't work together, though.

@97littleleaf11
Copy link
Collaborator

This issue can be closed.

@corydolphin
Copy link
Author

Thank you both! Closed.

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

No branches or pull requests

3 participants