python / python/mypy

Assertion failure crash: assert isinstance(node.node, TypeVarLikeExpr)

Offen
#20,283 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

crash topic-pep-695
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Crash Report

The snippet below crashes mypy 1.18.2 and the latest code from master (96fac3a2e4).

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 127, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "mypy/mypy/main.py", line 211, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "mypy/mypy/build.py", line 215, in build
    result = _build(
  File "mypy/mypy/build.py", line 294, in _build
    graph = dispatch(sources, manager, stdout)
  File "mypy/mypy/build.py", line 2945, in dispatch
    process_graph(graph, manager)
  File "mypy/mypy/build.py", line 3336, in process_graph
    done, still_working = manager.wait_for_done(graph)
  File "mypy/mypy/build.py", line 918, in wait_for_done
    process_stale_scc(graph, next_scc, self)
  File "mypy/mypy/build.py", line 3468, in process_stale_scc
    mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
  File "mypy/mypy/semanal_main.py", line 95, in semantic_analysis_for_scc
    process_top_levels(graph, scc, patches)
  File "mypy/mypy/semanal_main.py", line 233, in process_top_levels
    deferred, incomplete, progress = semantic_analyze_target(
  File "mypy/mypy/semanal_main.py", line 410, in semantic_analyze_target
    analyzer.refresh_partial(
  File "mypy/mypy/semanal.py", line 701, in refresh_partial
    self.refresh_top_level(node)
  File "mypy/mypy/semanal.py", line 719, in refresh_top_level
    self.accept(d)
  File "mypy/mypy/semanal.py", line 7563, in accept
    node.accept(self)
  File "mypy/mypy/nodes.py", line 1478, in accept
    return visitor.visit_class_def(self)
  File "mypy/mypy/semanal.py", line 1827, in visit_class_def
    self.analyze_class(defn)
  File "mypy/mypy/semanal.py", line 2044, in analyze_class
    self.analyze_class_body_common(defn)
  File "mypy/mypy/semanal.py", line 2090, in analyze_class_body_common
    defn.defs.accept(self)
  File "mypy/mypy/nodes.py", line 1573, in accept
    return visitor.visit_block(self)
  File "mypy/mypy/semanal.py", line 5375, in visit_block
    self.accept(s)
  File "mypy/mypy/semanal.py", line 7563, in accept
    node.accept(self)
    ~~~~~~~~~~~^^^^^^
  File "mypy/mypy/nodes.py", line 1478, in accept
    return visitor.visit_class_def(self)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "mypy/mypy/semanal.py", line 1827, in visit_class_def
    self.analyze_class(defn)
    ~~~~~~~~~~~~~~~~~~^^^^^^
  File "mypy/mypy/semanal.py", line 1969, in analyze_class
    bases, tvar_defs, is_protocol = self.clean_up_bases_and_infer_type_variables(
                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        defn, bases, context=defn
        ^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "mypy/mypy/semanal.py", line 2276, in clean_up_bases_and_infer_type_variables
    assert isinstance(node.node, TypeVarLikeExpr)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 

To Reproduce

class C:
    class Inner[T: C]:
        pass

    type T = c

Your Environment

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in mypy/semanal.py bei clean_up_bases_and_infer_type_variables(), identifiziert durch den Assertion-Traceback, und reproduziere den Absturz mit der bereitgestellten verschachtelten generischen Klasse und dem Typalias. Verfolge den Pfad der semantischen Analyse für dieses Beispiel und überprüfe, dass mypy bei der Verarbeitung keine AssertionError mehr auslöst.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
58/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.