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

Skip to content

[ty] Avoid panic for deferred dataclass field annotations#25444

Merged
charliermarsh merged 1 commit into
mainfrom
charlie/fix-ty-3493-deferred-annotations
May 29, 2026
Merged

[ty] Avoid panic for deferred dataclass field annotations#25444
charliermarsh merged 1 commit into
mainfrom
charlie/fix-ty-3493-deferred-annotations

Conversation

@charliermarsh

@charliermarsh charliermarsh commented May 29, 2026

Copy link
Copy Markdown
Member

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.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label May 29, 2026
@astral-sh-bot

astral-sh-bot Bot commented May 29, 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 91.94%. The percentage of expected errors that received a diagnostic held steady at 87.09%. The number of fully passing files held steady at 92/134.

@charliermarsh charliermarsh added the bug Something isn't working label May 29, 2026
@astral-sh-bot

astral-sh-bot Bot commented May 29, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented May 29, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@charliermarsh charliermarsh marked this pull request as ready for review May 29, 2026 07:09
@astral-sh-bot astral-sh-bot Bot requested a review from dhruvmanila May 29, 2026 07:09
@charliermarsh charliermarsh merged commit ae44d57 into main May 29, 2026
60 checks passed
@charliermarsh charliermarsh deleted the charlie/fix-ty-3493-deferred-annotations branch May 29, 2026 07:20
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: Type::find_name_in_mro() should return Some() when called on a meta-type

2 participants