Skip to content
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

Regression: crash when serializing alias to generic class method #8072

Closed
JukkaL opened this issue Dec 4, 2019 · 0 comments · Fixed by #8075
Closed

Regression: crash when serializing alias to generic class method #8072

JukkaL opened this issue Dec 4, 2019 · 0 comments · Fixed by #8075

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Dec 4, 2019

Type checking this program causes a crash during serialization of x:

from typing import TypeVar

T = TypeVar('T')

class C:
    @classmethod
    def f(cls, x: T) -> T: ...

x = C.f

Here's the traceback:

Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/jukka/src/mypy/mypy/__main__.py", line 12, in <module>
    main(None, sys.stdout, sys.stderr)
  File "/Users/jukka/src/mypy/mypy/main.py", line 89, in main
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/Users/jukka/src/mypy/mypy/build.py", line 167, in build
    sources, options, alt_lib_path, flush_errors, fscache, stdout, stderr, extra_plugins
  File "/Users/jukka/src/mypy/mypy/build.py", line 235, in _build
    graph = dispatch(sources, manager, stdout)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2620, in dispatch
    process_graph(graph, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2929, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 3047, in process_stale_scc
    graph[id].write_cache()
  File "/Users/jukka/src/mypy/mypy/build.py", line 2244, in write_cache
    self.manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 1410, in write_cache
    data = tree.serialize()
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 302, in serialize
    'names': self.names.serialize(self._fullname),
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 3083, in serialize
    data[key] = value.serialize(fullname, key)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 3021, in serialize
    data['node'] = self.node.serialize()
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 882, in serialize
    'type': None if self.type is None else self.type.serialize(),
  File "/Users/jukka/src/mypy/mypy/types.py", line 1218, in serialize
    'arg_types': [t.serialize() for t in self.arg_types],
  File "/Users/jukka/src/mypy/mypy/types.py", line 1218, in <listcomp>
    'arg_types': [t.serialize() for t in self.arg_types],
  File "/Users/jukka/src/mypy/mypy/types.py", line 885, in serialize
    assert not self.id.is_meta_var()
AssertionError

This is a regression introduced in #8021.

cc @ilevkivskyi

ilevkivskyi added a commit that referenced this issue Dec 4, 2019
Fixes #8072

The fix is straightforward, just copy the logic from the working case (see last test) to two other code paths. Note that only two first cases I added crash on master, but I also add the last one for completeness because I didn't find a similar existing test case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant