Conformance: align dataclass descriptor tests with runtime by ashishpatel26 · Pull Request #2299 · python/typing
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.yclass access is optional-error because those fields have no descriptor object in the class namespace.DC2.zclass access islist[str], because class access invokesDesc2.__get__(None, owner).dc2.x/dc2.y/dc2.zare the storedDesc2[...]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.
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.
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.
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.
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.yclass access remains optional-error because those fields have no class attribute at runtime.DC2.zclass access is asserted aslist[str], since class access invokesDesc2.__get__(None, owner).dc2.x/dc2.y/dc2.zare asserted as the storedDesc2[...]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
changed the title
Conformance: drop questionable non-data-descriptor dataclass tests
Conformance: align dataclass descriptor tests with runtime