stubtest invents _DT attribute on dataclasses
Nobody has claimed this yet.
- 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:
(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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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