Skip to content

Conformance: drop questionable non-data-descriptor dataclass tests#2299

Open
ashishpatel26 wants to merge 1 commit into
python:mainfrom
ashishpatel26:conformance-dataclass-descriptor-2259
Open

Conformance: drop questionable non-data-descriptor dataclass tests#2299
ashishpatel26 wants to merge 1 commit into
python:mainfrom
ashishpatel26:conformance-dataclass-descriptor-2259

Conversation

@ashishpatel26
Copy link
Copy Markdown

Closes #2259.

dataclasses_descriptors.py contained a DC2 section testing a non-data
descriptor (Desc2, only __get__) used as a dataclass field. Its assertions
do not match the runtime:

  • DC2.x / DC2.y raise AttributeError — there is no Desc2 object in the
    class namespace (those fields have no default).
  • dc2.x / dc2.y / dc2.z are the Desc2 instances stored as instance
    attributes; a non-data descriptor is shadowed by the instance dict, so
    __get__ never runs and the values are not int / 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 DC2 cases, keeping the well-defined data
descriptor (DC1) test, and rescoring:

  • mypy, pycroscope, ty: were Partial only because of the spurious DC2
    assertions → now Pass.
  • pyright, zuban: unchanged (Pass).
  • pyrefly: still Partial — it independently rejects DC1's data
    descriptor whose __get__/__set__ types differ; note updated accordingly.

The non-data-descriptor-in-dataclass behavior can be re-added once it is
specified.

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
@davidhalter
Copy link
Copy Markdown
Collaborator

davidhalter commented Jun 1, 2026

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
Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conformance suite: Questionable tests in dataclasses_descriptors.py

3 participants