`AssertionError: Must not defer during final iteration` with recursive class definition
Offen
Dieses Issue hat noch niemand übernommen.
crash
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Crash Report
mypy 2.1.0 and master (938dbe2f) crash on the snippet below.
Traceback
Traceback (most recent call last):
File ".venv-mypy/bin/mypy", line 6, in <module>
sys.exit(console_entry())
File "mypy/mypy/__main__.py", line 16, in console_entry
main()
File "mypy/mypy/main.py", line 154, in main
res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
File "mypy/mypy/main.py", line 244, in run_build
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "mypy/mypy/build.py", line 422, in build
result = build_inner(
File "mypy/mypy/build.py", line 537, in build_inner
graph = dispatch(sources, manager, stdout, connect_threads)
File "mypy/mypy/build.py", line 4134, in dispatch
process_graph(graph, manager)
File "mypy/mypy/build.py", line 4602, in process_graph
done, still_working, results = manager.wait_for_done(graph)
File "mypy/mypy/build.py", line 1478, in wait_for_done
process_stale_scc(graph, next_scc, self)
File "mypy/mypy/build.py", line 4769, in process_stale_scc
mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
File "mypy/mypy/semanal_main.py", line 91, in semantic_analysis_for_scc
process_top_levels(graph, scc, patches)
File "mypy/mypy/semanal_main.py", line 200, in process_top_levels
deferred, incomplete, progress = semantic_analyze_target(
File "mypy/mypy/semanal_main.py", line 380, 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 728, in refresh_top_level
self.accept(d)
File "mypy/mypy/semanal.py", line 7695, in accept
node.accept(self)
~~~~~~~~~~~^^^^^^
File "mypy/mypy/nodes.py", line 1727, in accept
return visitor.visit_class_def(self)
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "mypy/mypy/semanal.py", line 1840, in visit_class_def
self.analyze_class(defn)
~~~~~~~~~~~~~~~~~~^^^^^^
File "mypy/mypy/semanal.py", line 1991, in analyze_class
self.clean_up_bases_and_infer_type_variables(defn, bases, context=defn)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "mypy/mypy/semanal.py", line 2329, in clean_up_bases_and_infer_type_variables
result = self.analyze_class_typevar_declaration(base, has_type_var_tuple)
File "mypy/mypy/semanal.py", line 2409, in analyze_class_typevar_declaration
tvar = self.analyze_unbound_tvar(arg)
File "mypy/mypy/semanal.py", line 2435, in analyze_unbound_tvar
return self.analyze_unbound_tvar_impl(t)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
File "mypy/mypy/semanal.py", line 2444, in analyze_unbound_tvar_impl
self.record_incomplete_ref()
~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "mypy/mypy/semanal.py", line 7321, in record_incomplete_ref
self.defer()
~~~~~~~~~~^^
File "mypy/mypy/semanal.py", line 7296, in defer
assert not self.final_iteration, "Must not defer during final iteration"
^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Must not defer during final iteration
To Reproduce
from typing import Generic
class C(Generic[C]):
pass
Your Environment
- Mypy version used: 2.1.0 and 938dbe2f
- Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.14.5
- Operating system and version: Arch Linux
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere den Absturz mit dem bereitgestellten rekursiven Generic-Beispiel und verfolge dann den Pfad der semantischen Analyse durch mypy/semanal.py, insbesondere analyze_unbound_tvar_impl und defer. Erledigt bedeutet, dass das Snippet nicht mehr den AssertionError der letzten Iteration auslöst; im Report wird keine Datei für Regressionstests genannt, also finde die vorhandenen Tests der semantischen Analyse, bevor du Abdeckung hinzufügst.
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
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100