python / python/mypy

Crash in mypyc with recursive tuple TypeAlias

Aperta
#15,092 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug topic-mypyc
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug Report

Related to Issue #13795, using certain types of tuple in a recursive TypeAlias causes mypyc to crash, even though mypy reports no errors.

To Reproduce

from typing import TypeAlias

RuleItem: TypeAlias = tuple["RuleItem"] | str

def fun(value: RuleItem) -> None:
    pass

Also broken, with or without TypeAlias:

  • RuleItem: TypeAlias = Union[tuple["RuleItem"], str]
  • RuleItem: TypeAlias = Union[tuple["RuleItem", int], str]
  • RuleItem: TypeAlias = Union[tuple["RuleItem", "RuleItem"], str]
  • RuleItem: TypeAlias = Union[Tuple["RuleItem"], str]
  • RuleItem: TypeAlias = Tuple["RuleItem"]

(After importing Union and Tuple from typing, of course.)

But these work:

  • RuleItem: TypeAlias = Union[tuple[int], str]
  • RuleItem: TypeAlias = Union[tuple["RuleItem", ...], str]
  • RuleItem: TypeAlias = Union[list["RuleItem"], str]
  • RuleItem: TypeAlias = Union[set["RuleItem"], str]

(That second option turns out to be what I really wanted anyway.)

Actual Behavior

The mypy command reports no errors.

Running the mypyc command on an affected file emits no output (even with a --show-traceback option) and exits with status code 245.

Running the mypyc.build.mypycify Python function on an affected file emits no output, and crashes Python with status code 139.

Your Environment

  • Mypy version used: mypy 1.2.0 (compiled: yes)
  • Mypy command-line flags: --strict (optional)
  • Mypyc command-line flags: --show-traceback (optional)
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.10.6
  • OS version used: Ubuntu 22.04.1 LTS

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia eseguendo con mypy e mypyc l’esempio ricorsivo fornito di RuleItem, quindi esamina mypyc.build.mypycify e il percorso del compilatore che invoca. Conferma la correzione assicurandoti che gli alias interessati vengano compilati senza lo stato 245 o 139, mentre gli alias funzionanti elencati rimangano validi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.