Skip to content

pair of mutually recursive generic Protocol definitions #1587

@gertvdijk

Description

@gertvdijk

I've got a small Python typing showcase (currently using mypy) up at https://github.com/gertvdijk/mypy-sibling-generics-demo. Was wondering how ty would handle/show this, tried it out, but sadly it triggers ty to panic (tested at this current latest commit). It told me to create this bug report, so here I am. 😄

Steps to reproduce: clone that project, and running ty triggers it basically. I believe the output below includes all necessary info, but please LMK if you need anything else or even a smaller MRE.

$ git clone https://github.com/gertvdijk/mypy-sibling-generics-demo.git && cd mypy-sibling-generics-demo
$ uv add --dev ty
$ uv run ty check
error[panic]: Panicked at crates/ty_python_semantic/src/types/instance.rs:822:18 when checking `/path/to/mypy-sibling-generics-demo/foobar/client.py`: `Class wrapped by `Protocol` should be a protocol class`
info: This indicates a bug in ty.
info: If you could open an issue at https://github.com/astral-sh/ty/issues/new?title=%5Bpanic%5D, we'd be very appreciative!
info: Platform: linux x86_64
info: Version: 0.0.1-alpha.27
[...]
Full output
error[panic]: Panicked at crates/ty_python_semantic/src/types/instance.rs:822:18 when checking `/path/to/mypy-sibling-generics-demo/foobar/client.py`: `Class wrapped by `Protocol` should be a protocol class`
info: This indicates a bug in ty.
info: If you could open an issue at https://github.com/astral-sh/ty/issues/new?title=%5Bpanic%5D, we'd be very appreciative!
info: Platform: linux x86_64
info: Version: 0.0.1-alpha.27
info: Args: ["ty", "check"]
info: run with `RUST_BACKTRACE=1` environment variable to show the full backtrace information
info: query stacktrace:
   0: is_equivalent_to_object_inner(Id(25801))
             at crates/ty_python_semantic/src/types/instance.rs:663
             cycle heads: infer_definition_types(Id(300e)) -> iteration = 2
   1: infer_deferred_types(Id(300b))
             at crates/ty_python_semantic/src/types/infer.rs:141
             cycle heads: infer_definition_types(Id(300d)) -> iteration = 2, TypeVarInstance < 'db >::lazy_bound_(Id(1c801)) -> iteration = 2
   2: TypeVarInstance < 'db >::lazy_bound_(Id(1c800))
             at crates/ty_python_semantic/src/types.rs:8734
   3: infer_definition_types(Id(300e))
             at crates/ty_python_semantic/src/types/infer.rs:94
   4: infer_deferred_types(Id(300c))
             at crates/ty_python_semantic/src/types/infer.rs:141
   5: TypeVarInstance < 'db >::lazy_bound_(Id(1c801))
             at crates/ty_python_semantic/src/types.rs:8734
   6: infer_definition_types(Id(300d))
             at crates/ty_python_semantic/src/types/infer.rs:94
   7: infer_scope_types(Id(2400))
             at crates/ty_python_semantic/src/types/infer.rs:70
   8: check_file_impl(Id(c01))
             at crates/ty_project/src/lib.rs:535


error[panic]: Panicked at crates/ty_python_semantic/src/types/instance.rs:822:18 when checking `/path/to/mypy-sibling-generics-demo/foobar/server.py`: `Class wrapped by `Protocol` should be a protocol class`
info: This indicates a bug in ty.
info: If you could open an issue at https://github.com/astral-sh/ty/issues/new?title=%5Bpanic%5D, we'd be very appreciative!
info: Platform: linux x86_64
info: Version: 0.0.1-alpha.27
info: Args: ["ty", "check"]
info: run with `RUST_BACKTRACE=1` environment variable to show the full backtrace information
info: query stacktrace:
   0: is_equivalent_to_object_inner(Id(26801))
             at crates/ty_python_semantic/src/types/instance.rs:663
             cycle heads: infer_definition_types(Id(380d)) -> iteration = 2
   1: infer_deferred_types(Id(3808))
             at crates/ty_python_semantic/src/types/infer.rs:141
             cycle heads: infer_definition_types(Id(380c)) -> iteration = 2, TypeVarInstance < 'db >::lazy_bound_(Id(1e801)) -> iteration = 2
   2: TypeVarInstance < 'db >::lazy_bound_(Id(1e800))
             at crates/ty_python_semantic/src/types.rs:8734
   3: infer_definition_types(Id(380d))
             at crates/ty_python_semantic/src/types/infer.rs:94
   4: infer_deferred_types(Id(3809))
             at crates/ty_python_semantic/src/types/infer.rs:141
   5: TypeVarInstance < 'db >::lazy_bound_(Id(1e801))
             at crates/ty_python_semantic/src/types.rs:8734
   6: infer_definition_types(Id(380c))
             at crates/ty_python_semantic/src/types/infer.rs:94
   7: infer_scope_types(Id(2800))
             at crates/ty_python_semantic/src/types/infer.rs:70
   8: check_file_impl(Id(c00))
             at crates/ty_project/src/lib.rs:535


Found 2 diagnostics
WARN A fatal error occurred while checking some files. Not all project files were analyzed. See the diagnostics list above for details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions