python / python/mypy

Crash in mypyc with recursive tuple TypeAlias

Open
#15,092 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-mypyc
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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

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

Start by running the provided recursive RuleItem example through mypy and mypyc, then inspect mypyc.build.mypycify and the compiler path it invokes. Confirm the fix by ensuring affected aliases compile without status 245 or 139 while the listed working aliases remain valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.