python / python/mypy

Crash in mypyc with recursive tuple TypeAlias

オープン
#15,092 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug topic-mypyc
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提供されている再帰的な RuleItem の例を mypy と mypyc で実行し、次に mypyc.build.mypycify と、それが呼び出すコンパイラパスを調査します。影響を受けるエイリアスがステータス 245 または 139 なしでコンパイルされ、一覧にある動作するエイリアスが引き続き有効であることを確認して、修正を検証します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。