python / python/mypy

Assertion failure crash: assert not self.has_type_var_tuple_type

Open
#20,527 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

crash topic-pep-646 topic-pep-695
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Crash Report

The snippet below crashes mypy 1.19.1 and master (c41dbd0). The crash seems similar to #20287.

Traceback

Traceback (most recent call last):
  File ".venv-mypy/bin/mypy", line 7, in <module>
    sys.exit(console_entry())
  File "mypy/mypy/__main__.py", line 15, in console_entry
    main()
  File "mypy/mypy/main.py", line 135, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "mypy/mypy/main.py", line 219, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "mypy/mypy/build.py", line 320, in build
    result = build_inner(
  File "mypy/mypy/build.py", line 417, in build_inner
    graph = dispatch(sources, manager, stdout)
  File "mypy/mypy/build.py", line 3178, in dispatch
    process_graph(graph, manager)
  File "mypy/mypy/build.py", line 3588, in process_graph
    done, still_working, results = manager.wait_for_done(graph)
  File "mypy/mypy/build.py", line 1070, in wait_for_done
    process_stale_scc(graph, next_scc, self)
  File "mypy/mypy/build.py", line 3745, in process_stale_scc
    mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
  File "mypy/mypy/semanal_main.py", line 94, in semantic_analysis_for_scc
    process_top_levels(graph, scc, patches)
  File "mypy/mypy/semanal_main.py", line 232, in process_top_levels
    deferred, incomplete, progress = semantic_analyze_target(
  File "mypy/mypy/semanal_main.py", line 409, in semantic_analyze_target
    analyzer.refresh_partial(
  File "mypy/mypy/semanal.py", line 703, in refresh_partial
    self.refresh_top_level(node)
  File "mypy/mypy/semanal.py", line 721, in refresh_top_level
    self.accept(d)
  File "mypy/mypy/semanal.py", line 7598, in accept
    node.accept(self)
    ~~~~~~~~~~~^^^^^^
  File "mypy/mypy/nodes.py", line 1487, in accept
    return visitor.visit_class_def(self)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "mypy/mypy/semanal.py", line 1829, in visit_class_def
    self.analyze_class(defn)
    ~~~~~~~~~~~~~~~~~~^^^^^^
  File "mypy/mypy/semanal.py", line 2023, in analyze_class
    self.setup_type_vars(defn, tvar_defs)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "mypy/mypy/semanal.py", line 2065, in setup_type_vars
    defn.info.add_type_vars()
    ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "mypy/mypy/nodes.py", line 3620, in add_type_vars
    assert not self.has_type_var_tuple_type
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 

To Reproduce

class C[*T, *U](T, U):
    pass

Your Environment

  • Mypy version used: c41dbd0 (and 1.19.1)
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.13.11
  • Operating system and version: Arch Linux

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the crash with the provided class definition using mypy 1.19.1 or master. Start in mypy/nodes.py at add_type_vars and follow its callers through setup_type_vars in mypy/semanal.py. Done means the assertion no longer crashes mypy for this input and regression coverage protects the fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.