Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Recover from dynamic class code generator cycles#26167

Merged
charliermarsh merged 2 commits into
astral-sh:mainfrom
JamBalaya56562:ty-3720-dynamic-class-codegen-cycle
Jun 20, 2026
Merged

[ty] Recover from dynamic class code generator cycles#26167
charliermarsh merged 2 commits into
astral-sh:mainfrom
JamBalaya56562:ty-3720-dynamic-class-codegen-cycle

Conversation

@JamBalaya56562

@JamBalaya56562 JamBalaya56562 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Determining whether a dynamically created class has dataclass- or named-tuple-like behavior can re-enter the same query while resolving a self-referential base:

from abc import ABC
from typing import NamedTuple

T = type("T", NamedTuple("T", [("", "T")]), {})
T()
T = ABC

Prior to this change, code_generator_of_dynamic_class had no cycle recovery, so this input panicked with dependency graph cycle. This applies the same recovery used for static classes, treating a cyclic result as having no code generator rather than panicking.

Closes astral-sh/ty#3720.

Checking a self-referential dynamically-created class (e.g. the fuzzer-found
`type("T", NamedTuple("T", [("", "T")]), {})`) panicked with `dependency graph
cycle when querying code_generator_of_dynamic_class(...)`: the query re-enters
itself via `iter_mro` -> `deferred_explicit_bases` -> ... .

Its static-class sibling `code_generator_of_static_class` already recovers from
such cycles with `cycle_initial=|_, _, _| None`; apply the same recovery to the
dynamic-class query so a cycle resolves to "no code generator" instead of
panicking.

Fixes astral-sh/ty#3720.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@JamBalaya56562 JamBalaya56562 requested a review from a team as a code owner June 20, 2026 04:00
@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Jun 20, 2026
@astral-sh-bot astral-sh-bot Bot requested a review from charliermarsh June 20, 2026 04:01
@astral-sh-bot

astral-sh-bot Bot commented Jun 20, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 94.37%. The percentage of expected errors that received a diagnostic held steady at 89.00%. The number of fully passing files held steady at 94/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 20, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Jun 20, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@charliermarsh charliermarsh changed the title [ty] Recover from Salsa cycles in code_generator_of_dynamic_class [ty] Recover from Salsa cycles in code_generator_of_dynamic_class Jun 20, 2026
@charliermarsh charliermarsh added the bug Something isn't working label Jun 20, 2026
@charliermarsh charliermarsh changed the title [ty] Recover from Salsa cycles in code_generator_of_dynamic_class [ty] Recover from dynamic class code generator cycles Jun 20, 2026
@charliermarsh charliermarsh merged commit 121f836 into astral-sh:main Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic: dependency graph cycle when querying code_generator_of_dynamic_class

2 participants