Skip to content

Yet another "AssertionError: Should never get here in normal mode" #5631

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 Sep 18, 2018 · 6 comments
Closed

Yet another "AssertionError: Should never get here in normal mode" #5631

pradyunsg opened this issue Sep 18, 2018 · 6 comments

Comments

@pradyunsg
Copy link
Member

Similar crash as in #5192; happening with current pip master.

$ # In a venv with only mypy installed.
$ git clone https://github.com/pypa/pip.git --depth=1
[...]
$ cd pip
$ git fetch origin deeb1e493d8947a957c86bf256e7f5fa91c92e52
$ git checkout deeb1e493d8947a957c86bf256e7f5fa91c92e52
$ # Populate the cache; there's 2 errors as expected.
$ mypy src
[...]
$ # This run will crash
$ mypy src
Traceback (most recent call last):
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/bin/mypy", line 11, in <module>
    sys.exit(console_entry())
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/__main__.py", line 7, in console_entry
    main(None)
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/main.py", line 91, in main
    res = type_check_only(sources, bin_dir, options, flush_errors, fscache)  # noqa
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/main.py", line 148, in type_check_only
    fscache=fscache)
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/build.py", line 183, in build
    flush_errors, fscache)
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/build.py", line 356, in _build
    graph = dispatch(sources, manager)
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/build.py", line 2543, in dispatch
    process_graph(graph, manager)
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/build.py", line 2833, in process_graph
    process_fresh_modules(graph, prev_scc, manager)
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/build.py", line 2919, in process_fresh_modules
    graph[id].fix_cross_refs()
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/build.py", line 1927, in fix_cross_refs
    self.options.use_fine_grained_cache)
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/fixup.py", line 24, in fixup_module
    node_fixer.visit_symbol_table(tree.names)
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/fixup.py", line 89, in visit_symbol_table
    value.node.accept(self)
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/nodes.py", line 2582, in accept
    return visitor.visit_type_alias(self)
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/fixup.py", line 135, in visit_type_alias
    a.target.accept(self.type_fixer)
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/types.py", line 501, in accept
    return visitor.visit_instance(self)
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/fixup.py", line 149, in visit_instance
    inst.type = lookup_qualified_typeinfo(self.modules, type_ref, self.quick_and_dirty)
  File "/Users/pradyunsg/.virtualenvs/tmp-646a2fd8b91d920/lib/python3.7/site-packages/mypy/fixup.py", line 239, in lookup_qualified_typeinfo
    assert quick_and_dirty, "Should never get here in normal mode"
AssertionError: Should never get here in normal mode

I haven't tested with master (internet access is patchy for me atm) but this does occur for mypy 0.630 on Python 3.7.0.

@pradyunsg
Copy link
Member Author

Doing rm -r .mypy_cache/3.7/pip/_vendor/ before a second run prevents this crash.

@ilevkivskyi
Copy link
Member

I still see the crash on master. I am investigating now.

@ilevkivskyi
Copy link
Member

ilevkivskyi commented Sep 18, 2018

OK, it looks like the code causing the crash is also similar to the previous one (now in urllib3):

try:  # Python 3:
    # Not a no-op, we're adding this to the namespace so it can be imported.
    ConnectionError = ConnectionError
except NameError:  # Python 2:
    class ConnectionError(Exception):
        pass

I will try to write a simple repro now.

@ilevkivskyi
Copy link
Member

OK, the minimal repro is as simple as this:

[case testOverrideByIdemAlias]
import a
[file a.py]
import lib
x = 1
[file a.py.2]
import lib
x = 2
[file lib.py]
C = C
class C:  # type: ignore
    pass
[out]
[out2]

Also it looks like this is a regression since 0.620, caused by #5565

The fix is straightforward, the only question is does this warrant a bug-fix release 0.631?

@JukkaL
Copy link
Collaborator

JukkaL commented Sep 18, 2018

The fix is straightforward, the only question is does this warrant a bug-fix release 0.631?

Let's wait first if there are other reports of this issue. If not, we can release 0.640 in ~two weeks, on a slightly accelerated schedule. If there are other reports, a bug-fix release may make sense.

ilevkivskyi added a commit that referenced this issue Sep 19, 2018
Fixes #5631

Unfortunately one still needs to use `# type: ignores`, mypy has troubles understanding complex conditional definitions like in the issue:
```python
try:
    ConnectionError = ConnectionError
except NameError:
    class ConnectionError(Exception):
        pass
```
But this is a separate problem, that is harder to solve.
@pradyunsg
Copy link
Member Author

Thanks for this fix! ^.^

(late post)

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