◐ Shell
clean mode source ↗

Conformance: align dataclass descriptor tests with runtime by ashishpatel26 · Pull Request #2299 · python/typing

@ashishpatel26

Closes #2259.

dataclasses_descriptors.py keeps coverage for the non-data descriptor (Desc2, only __get__) used as a dataclass field, but aligns the expected behavior with runtime descriptor lookup:

  • DC2.x / DC2.y class access is optional-error because those fields have no descriptor object in the class namespace.
  • DC2.z class access is list[str], because class access invokes Desc2.__get__(None, owner).
  • dc2.x / dc2.y / dc2.z are the stored Desc2[...] objects, because non-data descriptors are shadowed by the instance __dict__ after dataclass __init__ assigns the fields.

The result TOMLs and summary HTML have been regenerated. With the runtime-correct asserts, all six checkers are scored Partial for dataclasses_descriptors.

@davidhalter

What - in your opinion - would be the proper solution for these cases? I generally want to avoid removing tests and rather expand the docs or correct the tests. There are a lot of cases where the spec is lacking and I want to avoid removing them all.

In my opinion it is very valuable to standardize descriptors on Dataclasses. I'm not particularly invested in how they are standardized, but I would like to have that to be one specific way.

@JelleZijlstra

As I wrote in the issue, pyrefly's behavior seemed the most correct to me. I'm not sure this behavior needs to be specified in the typing spec in much detail since what I view as the correct behavior primarily reflects the runtime.

@davidhalter

pyrefly's behavior seemed the most correct to me. I'm not sure this behavior needs to be specified in the typing spec in much detail since what I view as the correct behavior primarily reflects the runtime.

I agree that this does not necessarily need to be specified. However I would still prefer to make the pyrefly behavior part of the tests than to drop the test.

@ashishpatel26

Thanks both. I reworked this to keep the non-data descriptor coverage rather than deleting it, and aligned the DC2 case with runtime descriptor lookup:

  • DC2.x / DC2.y class access remains optional-error because those fields have no class attribute at runtime.
  • DC2.z class access is asserted as list[str], since class access invokes Desc2.__get__(None, owner).
  • dc2.x / dc2.y / dc2.z are asserted as the stored Desc2[...] objects, because a non-data descriptor is shadowed by the instance __dict__ after dataclass __init__ assigns the fields.

I regenerated the result files and summary HTML for this test. With the runtime-correct asserts, all six checker result TOMLs are now scored Partial for dataclasses_descriptors.

@ashishpatel26 ashishpatel26 changed the title Conformance: drop questionable non-data-descriptor dataclass tests Conformance: align dataclass descriptor tests with runtime

Jun 5, 2026