python / python/mypy

Mypyc produces module that crashes (segmentation fault) when executed

Open
#18,992 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

compiled.py:

from typing import Generic, TypeVar

_T = TypeVar("_T")

class Bar(Generic[_T]):
    def __init__(self) -> None:
        self.value: str = 'start'
    def __get__(self, instance: _T, owner: type[_T] | None = None) -> str:
        return self.value
    def __set__(self, instance: _T, value: str) -> None:
        self.value = value

class Foo(object):
    bar: Bar = Bar()

Compiled with python3 -m mypyc compiled.py.

test.py:

import compiled

print("hello")

f = compiled.Foo()
print(f.bar)

f.bar = 'test'
print(f.bar)

And running with:

$ python3 test.py
hello
<compiled.Bar object at 0x7464e7774310>
Segmentation fault

Using current master of mypyc:

$ python3 -m mypyc --version
mypy 1.16.0+dev.7b4f6311e29452cc8d4ddb78331d0047c8b17e93.dirty (compiled: no)

Using Python 3.13.1

If running with python3 directly:

$ python3 test.py
hello
start
test

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

Reproduce the crash by compiling compiled.py with python3 -m mypyc and running test.py under Python 3.13.1. Compare the compiled behavior with direct Python execution, focusing on the generic descriptor and Foo.bar access. Done means the compiled module prints hello, start, and test without a segmentation fault.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.