Skip to content

[ty] Preserve declaration order when synthesizing class fields#25249

Draft
charliermarsh wants to merge 1 commit into
mainfrom
charlie/declaration-order
Draft

[ty] Preserve declaration order when synthesizing class fields#25249
charliermarsh wants to merge 1 commit into
mainfrom
charlie/declaration-order

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

Summary

Prior to this change, field synthesis could accidentally follow symbol-table order instead of class-body declaration order in pathological cases like:

from dataclasses import InitVar, dataclass
from ty_extensions import Top

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

Here, int can be interned before its own declaration because it already appears in Top[int].

This PR carries a stable declaration ordinal through declaration lookup and uses it when building own_fields().

Closes astral-sh/ty#3493.

@charliermarsh charliermarsh added bug Something isn't working ty Multi-file analysis & type inference labels May 19, 2026
@charliermarsh charliermarsh force-pushed the charlie/declaration-order branch from eadeec6 to bba1d8c Compare May 19, 2026 23:56
@charliermarsh charliermarsh force-pushed the charlie/declaration-order branch from bba1d8c to 33a711c Compare May 20, 2026 00:03
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

1 participant