Conformance: drop questionable non-data-descriptor dataclass tests#2299
Conformance: drop questionable non-data-descriptor dataclass tests#2299ashishpatel26 wants to merge 1 commit into
Conversation
The DC2 portion of dataclasses_descriptors.py asserted types for a non-data descriptor (only __get__) used as a dataclass field that do not match the runtime: DC2.x/DC2.y raise AttributeError, and dc2.x/y/z are the descriptor objects themselves (a non-data descriptor is shadowed by the instance dict), not the __get__ return type. This behavior is under-specified, and type checkers disagree. Remove the DC2 cases, keeping the well-defined data descriptor (DC1) test. mypy, pycroscope, and ty no longer fail on the spurious assertions. Closes python#2259
|
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. |
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. |
Closes #2259.
dataclasses_descriptors.pycontained aDC2section testing a non-datadescriptor (
Desc2, only__get__) used as a dataclass field. Its assertionsdo not match the runtime:
DC2.x/DC2.yraiseAttributeError— there is noDesc2object in theclass namespace (those fields have no default).
dc2.x/dc2.y/dc2.zare theDesc2instances stored as instanceattributes; a non-data descriptor is shadowed by the instance dict, so
__get__never runs and the values are notint/str.As noted in the issue, this behavior is under-specified and type checkers
disagree (pyrefly rejects it; mypy and pyright accept the incorrect
assertions). This removes the
DC2cases, keeping the well-defined datadescriptor (
DC1) test, and rescoring:Partialonly because of the spuriousDC2assertions → now
Pass.Pass).Partial— it independently rejectsDC1's datadescriptor whose
__get__/__set__types differ; note updated accordingly.The non-data-descriptor-in-dataclass behavior can be re-added once it is
specified.