[ty] Avoid panic for deferred dataclass field annotations by charliermarsh · Pull Request #25444 · astral-sh/ruff (original) (raw)

Summary

I fixed astral-sh/ty#3493 in #25249, but missed the case of deferred evaluation for annotations... For deferred evaluation, when we then checked whether that field was a descriptor, class_member_with_policy attempted meta-type lookup on the cycle marker itself and panicked.

E.g., on Python 3.14, where annotations are deferred by default:

from dataclasses import InitVar, dataclass from ty_extensions import Top

@dataclass class C: a: Top[int] int: InitVar[int] = 0

C()

We now apply the materialized divergent fallback before class-member lookup, consistent with the other lookup and descriptor operations. (The example reports the expected missing argument for a instead of panicking, and is covered under Python 3.14.)

Closes astral-sh/ty#3493.