ruff/crates/ty_python_semantic/resources/mdtest
Alex Waygood 35bfcff24d
[ty] Add failing mdtest for known Protocol panic (#21594)
## Summary

This PR adds a failing mdtest for the panic in
https://github.com/astral-sh/ty/issues/1587. The added snippet currently
panics with this query stacktrace:

```
error[panic]: Panicked at /Users/alexw/.cargo/git/checkouts/salsa-e6f3bb7c2a062968/17bc55d/src/function/execute.rs:321:21 when checking `/Users/alexw/dev/ruff/foo.py`: `ClassLiteral < 'db >::explicit_bases_(Id(4c09)): execute: too many cycle iterations`
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: macos aarch64
info: Version: ruff/0.14.5+105 (d24c891a4 2025-11-22)
info: Args: ["target/debug/ty", "check", "foo.py", "--python-version=3.14"]
info: run with `RUST_BACKTRACE=1` environment variable to show the full backtrace information
info: query stacktrace:
   0: cached_protocol_interface(Id(6805))
             at crates/ty_python_semantic/src/types/protocol_class.rs:795
   1: is_equivalent_to_object_inner(Id(8003))
             at crates/ty_python_semantic/src/types/instance.rs:667
   2: infer_deferred_types(Id(1406))
             at crates/ty_python_semantic/src/types/infer.rs:140
             cycle heads: infer_definition_types(Id(140b)) -> iteration = 200, TypeVarInstance < 'db >::lazy_bound_(Id(5802)) -> iteration = 200
   3: TypeVarInstance < 'db >::lazy_bound_(Id(5803))
             at crates/ty_python_semantic/src/types.rs:8827
   4: infer_definition_types(Id(140c))
             at crates/ty_python_semantic/src/types/infer.rs:94
   5: infer_deferred_types(Id(1405))
             at crates/ty_python_semantic/src/types/infer.rs:140
   6: TypeVarInstance < 'db >::lazy_bound_(Id(5802))
             at crates/ty_python_semantic/src/types.rs:8827
   7: infer_definition_types(Id(140b))
             at crates/ty_python_semantic/src/types/infer.rs:94
   8: infer_scope_types(Id(1000))
             at crates/ty_python_semantic/src/types/infer.rs:70
   9: check_file_impl(Id(c00))
             at crates/ty_project/src/lib.rs:535
```

It's not totally clear to me how to fix this or to what extent it might
be a bug in our `Protocol` internals rather than a bug in our `TypeVar`
internals. (It's sort of interesting that we're trying to evaluate the
upper bound of any `TypeVar`s here!) @carljm suggested that it would be
a good idea to add a failing mdtest in the meantime to document the
panic, which I agree with.

## Test Plan

I verified that we panic on this snippet, and that the test fails if I
remove the `expect-panic` assertion or if I change the asserted error
message.

I experimented with ways of minimizing the snippet further, but I think
any further minimization takes the snippet further away from something a
user would actually be likely to write -- so I think is probably
counterproductive. The failing test added in this PR isn't unreasonable
code at the end of the day; I've seen Python like it in the wild.
2025-11-24 08:21:15 +00:00
..
annotations [ty] support PEP 613 type aliases (#21394) 2025-11-20 17:59:35 -08:00
assignment [ty] Fix panic for unclosed string literal in type annotation position (#21592) 2025-11-23 16:51:58 +01:00
binary [ty] support PEP 613 type aliases (#21394) 2025-11-20 17:59:35 -08:00
boolean
boundness_declaredness
call [ty] support PEP 613 type aliases (#21394) 2025-11-20 17:59:35 -08:00
class [ty] Check method definitions on subclasses for Liskov violations (#21436) 2025-11-23 18:08:15 +00:00
comparison [ty] Check method definitions on subclasses for Liskov violations (#21436) 2025-11-23 18:08:15 +00:00
comprehensions [ty] fix global symbol lookup from eager scopes (#21317) 2025-11-12 10:15:51 -08:00
conditional
dataclasses [ty] Dataclasses: __hash__ semantics and unsafe_hash (#21470) 2025-11-16 09:52:30 +00:00
declaration
diagnostics [ty] implement TypedDict structural assignment (#21467) 2025-11-20 13:15:28 -08:00
directives [ty] Custom concise diagnostic messages (#21498) 2025-11-18 09:35:40 +01:00
doc
exception [ty] Improve diagnostics for invalid exceptions (#21475) 2025-11-15 22:12:00 +00:00
expression [ty] Check method definitions on subclasses for Liskov violations (#21436) 2025-11-23 18:08:15 +00:00
function [ty] Sync vendored typeshed stubs (#21466) 2025-11-15 17:12:32 +00:00
generics [ty] Remove brittle constraint set reveal tests (#21568) 2025-11-21 13:57:55 -05:00
ide_support [ty] Fixup a few details around version-specific dataclass features (#21453) 2025-11-14 15:04:55 +00:00
import [ty] Improve diagnostics when a submodule is not available as an attribute on a module-literal type (#21561) 2025-11-22 14:07:48 +00:00
literal [ty] Type inference for genererator expressions (#21437) 2025-11-14 13:04:11 +00:00
loops [ty] Fix bug where ty would think all types had an __mro__ attribute (#20995) 2025-10-27 11:19:12 +00:00
narrow [ty] Eagerly evaluate types.UnionType elements as type expressions (#21531) 2025-11-20 17:28:48 +01:00
regression [ty] fix global symbol lookup from eager scopes (#21317) 2025-11-12 10:15:51 -08:00
scopes [ty] Make __getattr__ available for ModuleType instances (#21450) 2025-11-14 13:59:14 +01:00
shadowing
snapshots [ty] Check method definitions on subclasses for Liskov violations (#21436) 2025-11-23 18:08:15 +00:00
stubs [ty] Better invalid-assignment diagnostics (#21476) 2025-11-18 14:31:04 +01:00
subscript [ty] implement TypedDict structural assignment (#21467) 2025-11-20 13:15:28 -08:00
suppressions [ty] Better invalid-assignment diagnostics (#21476) 2025-11-18 14:31:04 +01:00
type_compendium [ty] Improve literal promotion heuristics (#21439) 2025-11-14 16:13:56 -05:00
type_of [ty] Support type[…] and Type[…] in implicit type aliases (#21421) 2025-11-13 19:02:24 +01:00
type_properties [ty] Improve diagnostics when a submodule is not available as an attribute on a module-literal type (#21561) 2025-11-22 14:07:48 +00:00
type_qualifiers [ty] Fix false positive for Final attribute assignment in __init__ (#21158) 2025-11-11 12:54:05 -08:00
unary
with
.mdformat.toml
async.md
attributes.md [ty] Check method definitions on subclasses for Liskov violations (#21436) 2025-11-23 18:08:15 +00:00
bidirectional.md [ty] Improve literal promotion heuristics (#21439) 2025-11-14 16:13:56 -05:00
classes.md [ty] Fix bug where ty would think all types had an __mro__ attribute (#20995) 2025-10-27 11:19:12 +00:00
cycle.md [ty] Avoid ever-growing default types (#20991) 2025-10-21 19:13:36 +02:00
decorators.md
del.md
deprecated.md
descriptor_protocol.md [ty] Use the return type of __get__ for descriptor lookups even when __get__ is called with incorrect arguments (#21424) 2025-11-13 12:05:10 +00:00
enums.md [ty] Custom concise diagnostic messages (#21498) 2025-11-18 09:35:40 +01:00
exhaustiveness_checking.md [ty] Improve exhaustiveness analysis for type variables with bounds or constraints (#21172) 2025-10-31 16:51:11 -04:00
final.md
implicit_type_aliases.md [ty] Add type definitions for Type::SpecialForms (#21544) 2025-11-20 18:14:30 +00:00
instance_layout_conflict.md
intersection_types.md [ty] Use "cannot" consistently over "can not" (#21255) 2025-11-03 10:38:20 -05:00
invalid_syntax.md [ty] Implicit type aliases: Add support for typing.Union (#21363) 2025-11-12 12:59:14 +01:00
known_constants.md
liskov.md [ty] Check method definitions on subclasses for Liskov violations (#21436) 2025-11-23 18:08:15 +00:00
literal_promotion.md [ty] Narrow type context during literal promotion in generic class constructors (#21574) 2025-11-21 17:05:32 -05:00
mdtest_config.md
mdtest_custom_typeshed.md
metaclass.md
mro.md [ty] Sync vendored typeshed stubs (#21466) 2025-11-15 17:12:32 +00:00
named_tuple.md [ty] Fix bug where ty would think all types had an __mro__ attribute (#20995) 2025-10-27 11:19:12 +00:00
overloads.md [ty] Infer type of self for decorated methods and properties (#21123) 2025-10-29 21:22:38 +00:00
paramspec.md [ty] Ensure annotation/type expressions in stub files are always deferred (#21401) 2025-11-13 17:14:54 +00:00
pep613_type_aliases.md [ty] support PEP 613 type aliases (#21394) 2025-11-20 17:59:35 -08:00
pep695_type_aliases.md [ty] support PEP 613 type aliases (#21394) 2025-11-20 17:59:35 -08:00
properties.md [ty] Use the return type of __get__ for descriptor lookups even when __get__ is called with incorrect arguments (#21424) 2025-11-13 12:05:10 +00:00
protocols.md [ty] Add failing mdtest for known Protocol panic (#21594) 2025-11-24 08:21:15 +00:00
public_types.md [ty] Disambiguate classes that live in different modules but have the same fully qualified names (#20756) 2025-10-08 18:27:40 +01:00
statically_known_branches.md
sys_platform.md
sys_version_info.md [ty] support PEP 613 type aliases (#21394) 2025-11-20 17:59:35 -08:00
t_strings.md
terminal_statements.md
ty_extensions.md [ty] Use "cannot" consistently over "can not" (#21255) 2025-11-03 10:38:20 -05:00
typed_dict.md [ty] implement TypedDict structural assignment (#21467) 2025-11-20 13:15:28 -08:00
union_types.md
unpacking.md
unreachable.md [ty] Use "cannot" consistently over "can not" (#21255) 2025-11-03 10:38:20 -05:00