python / python/mypy

stubtest invents _DT attribute on dataclasses

Open
#18,811 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-stubtest
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

Cf. python/typeshed#13645 and https://github.com/python/typeshed/actions/runs/13905970431/job/38908976156

When comparing dataclass with @dataclass(order=True) using stubtest, stubtest complains that X._DT is not present at runtime (where X is the dataclass).

This is probably due to synthesizing a TypeVar:

https://github.com/python/mypy/blob/5c87e972d3c2c3c1f6229e1a655c4b903207dd32/mypy/plugins/dataclasses.py#L86

(Thanks, @AlexWaygood.)

Your Environment

  • Mypy version used: 1.15.0
  • Python version used: 3.12.9

Command run was:

/tmp/stubtest-1u57o6se/bin/pip install fpdf2[]==2.8.2 mypy==1.15.0 Pillow>=10.3.0 cryptography
MYPYPATH=stubs/fpdf2 /tmp/stubtest-1u57o6se/bin/python -m mypy.stubtest --custom-typeshed-dir . fpdf --allowlist stubs/fpdf2/@tests/stubtest_allowlist.txt

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with the provided stubtest command and inspect mypy/plugins/dataclasses.py around line 86, where the issue points to TypeVar synthesis. Compare the generated dataclass attributes with runtime attributes, then verify that stubtest no longer reports X._DT as missing for an orderable dataclass.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.