Skip to content

Internal error analyzing generic protocol with nested class #8397

Closed
@damianw

Description

@damianw

Mypy crashes when analyzing a generic protocol with a nested class, up to and including the latest version from Git master (770276d70c3892f4154be85b96ec028705941184).

test.py

from typing import TypeVar, Protocol

T = TypeVar("T", covariant=True)


class MyProtocol(Protocol[T]):
    class Nested:
        pass

Command

python3.8 -m mypy --show-traceback test.py
(default configuration)

Output

test.py:6: 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.770+dev.770276d70c3892f4154be85b96ec028705941184
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/__main__.py", line 12, in <module>
    main(None, sys.stdout, sys.stderr)
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/main.py", line 89, in main
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/build.py", line 165, in build
    result = _build(
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/build.py", line 234, in _build
    graph = dispatch(sources, manager, stdout)
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/build.py", line 2631, in dispatch
    process_graph(graph, manager)
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/build.py", line 2938, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/build.py", line 3037, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/build.py", line 2130, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/checker.py", line 293, in check_first_pass
    self.accept(d)
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/checker.py", line 400, in accept
    stmt.accept(self)
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/nodes.py", line 939, in accept
    return visitor.visit_class_def(self)
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/checker.py", line 1755, in visit_class_def
    self.check_protocol_variance(defn)
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/checker.py", line 1823, in check_protocol_variance
    if is_subtype(down, up, ignore_declared_variance=True):
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/subtypes.py", line 93, in is_subtype
    return _is_subtype(left, right,
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/subtypes.py", line 135, in _is_subtype
    return left.accept(SubtypeVisitor(orig_right,
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/types.py", line 794, in accept
    return visitor.visit_instance(self)
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/subtypes.py", line 259, in visit_instance
    if right.type.is_protocol and is_protocol_implementation(left, right):
  File "/Users/.../.virtualenvs/.../lib/python3.8/site-packages/mypy/subtypes.py", line 530, in is_protocol_implementation
    assert supertype is not None
AssertionError:
test.py:6: : note: use --pdb to drop into pdb

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions