Skip to content

Indefinite hang with recursive aliases on ty>=0.0.66 #4205

Description

@jamtat

Summary

Here's a repo that reproduces the issue: https://github.com/jamtat/ty-hang-repro

Example code pasted here for convenience:

"""Minimal reproducer: ty >=0.0.66 never terminates on this file.
 
    `uv run ty check` hangs indefinitely, consuming 100% CPU on one thread.
 
Required to reproduce the hang:
 
  1. a self-recursive `Sequence[Rec]` union arm
  2. a second arm that is a Mapping (or dict) keyed by `Any`
  3. an `==` narrowing of a value of that type
  4. any read of the narrowed binding afterwards
"""
 
from collections.abc import Mapping, Sequence
from typing import Any
 
type Rec = Sequence[Rec] | Mapping[Any, int]
 
 
def g(x: Rec):
    assert x == 0
    _ = x

Version

>=0.0.66

Metadata

Metadata

Assignees

Labels

cyclesRecursive type definitions, self-referential inference, cycle detection, and cycle recoveryhangnarrowingrelated to flow-sensitive type narrowingperformancePotential performance improvementset-theoretic typesunions, intersections and moretype aliases

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions