Conformance: drop questionable non-data-descriptor dataclass tests#2299
Open
ashishpatel26 wants to merge 1 commit into
Open
Conformance: drop questionable non-data-descriptor dataclass tests#2299ashishpatel26 wants to merge 1 commit into
ashishpatel26 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
Collaborator
|
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. |
Member
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.