Skip to content

[ty] Respect kw_only overwrites in dataclasses#23930

Merged
sharkdp merged 1 commit intomainfrom
david/fix-3033
Mar 13, 2026
Merged

[ty] Respect kw_only overwrites in dataclasses#23930
sharkdp merged 1 commit intomainfrom
david/fix-3033

Conversation

@sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Mar 13, 2026

Summary

The kw_only dataclass parameter was previously not correctly detected as an override for kw_only_default.

closes astral-sh/ty#3033

Test Plan

Extended Markdown tests.

@sharkdp sharkdp added the ty Multi-file analysis & type inference label Mar 13, 2026
@astral-sh-bot astral-sh-bot bot requested a review from oconnor663 March 13, 2026 10:57
@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 13, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 85.29%. The percentage of expected errors that received a diagnostic held steady at 78.13%. The number of fully passing files held steady at 64/132.

@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 13, 2026

mypy_primer results

Changes were detected when running on open source projects
scikit-build-core (https://github.com/scikit-build/scikit-build-core)
- src/scikit_build_core/build/wheel.py:99:20: error[no-matching-overload] No overload of bound method `__init__` matches arguments
- Found 58 diagnostics
+ Found 57 diagnostics

@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 13, 2026

Memory usage report

Memory usage unchanged ✅

if transformer_params.flags(db).contains(DataclassTransformerFlags::KW_ONLY_DEFAULT)
);
*kw = Some(class_kw_only_default);
*kw = Some(self.has_dataclass_param(db, field_policy, DataclassFlags::KW_ONLY));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the TODO was added (in d2aabea) before we added the self.has_dataclass_param() method (in 938c1c5) that handles merging the two sources of dataclass params for you? And the bug here was caused by the fact that we forgot to update this callsite to use the new method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly right.

@AlexWaygood AlexWaygood added the bug Something isn't working label Mar 13, 2026
@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 13, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-await 40 0 0
invalid-return-type 1 0 0
Total 41 0 0

Full report with detailed diff (timing results)

@sharkdp sharkdp merged commit a923421 into main Mar 13, 2026
53 of 54 checks passed
@sharkdp sharkdp deleted the david/fix-3033 branch March 13, 2026 11:13
carljm added a commit that referenced this pull request Mar 13, 2026
* main: (94 commits)
  Fix shell injection via `shell=True` in subprocess calls (#23894)
  [ty] Refactor `relation.rs` to store state on a struct rather than passing around 7 arguments every time we recurse (#23837)
  Don't return code actions for non-Python documents (#23905)
  [ty] Make the default database truly statically infallible (#23929)
  [ty] Add `Download` button to ty playground which creates a zip export (#23478)
  [ty] Respect `kw_only` overwrites in dataclasses (#23930)
  [ty] Clarify in diagnostics that `from __future__ import annotations` only stringifies type annotations (#23928)
  [ty]  Add a `Copy Markdown` button to playground (#23002)
  [ty] Fix folding range classification of lines starting with `#` (#23831)
  [ty] Fix folding ranges for notebooks (#23830)
  [ty] fix too-many-cycle panics when inferring literal type loop variables (#23875)
  Add `RegularCallableTypeOf` and `into_regular_callable` in `ty_extensions` (#23909)
  [ty] treat properties as full structural types (#23925)
  [ty] Avoid duplicated work during multi-inference (#23923)
  [ty]: make `possibly-missing-attribute` ignored by default
  [ty]: split out `possibly-missing-submodule` from `possibly-missing-attribute`
  Update astral-sh/setup-uv action to v7.5.0 (#23922)
  [ty] Show truthiness in ConstraintSet display and simplify falsy error message (#23913)
  Bump 0.15.6 (#23919)
  [ty] Narrow type context during collection literal inference (#23844)
  ...
sharkdp added a commit that referenced this pull request Mar 13, 2026
## Summary

Similar in spirit to #23930. This
is the last remaining place (I think) where we determined the presence
of dataclass parameters in a way that did not account for defaults that
were set on the model base.

## Test Plan

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

Labels

bug Something isn't working ecosystem-analyzer ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dataclass_transform ignores kw_only argument in class definition (Metaclass Keyword Argument)

3 participants