Skip to content

Crash on diverging recursive generic protocols #17326

Open
@randolf-scholz

Description

@randolf-scholz

EDIT: Although the original repro is not causing a crash anymore, the underlying issue is still there, see #17326 (comment)

Crash Report

Not sure how to title this, the following example produces a segfault, I simplified it from more complicated code. It seems to be multicausal, removing the Literal makes it disappear, so does removing the __or__ operator on Transform.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.12&gist=2409c60fc1d5734569f6ab55344a85f0

from typing import Any, Literal, Protocol, TypeVar, overload

X = TypeVar("X")
Y = TypeVar("Y")
Z = TypeVar("Z")
X2 = TypeVar("X2")
Y2 = TypeVar("Y2")


class Transform(Protocol[X, Y]):
    def __or__(
        self, other: "Transform[X2, Y2]", /
    ) -> "Transform[tuple[X, X2], tuple[Y, Y2]]": ...


@overload  # 1 arg
def chain_encoders(
    e: Transform[X, Y], /, *, simplify: Literal[True] = ...
) -> Transform[X, Y]: ...
@overload  # ≥2 args
def chain_encoders(
    *es: *tuple[Transform[Any, Y], *tuple[Transform, ...], Transform[X, Any]],
    simplify: Literal[True] = ...,
) -> Transform[X, Y]: ...
def chain_encoders(*encoders: Transform, simplify: bool = True) -> Transform:
    r"""Chain encoders."""

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions