Skip to content

Conversation

@sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Nov 15, 2025

Summary

We previously only allowed models to overwrite the {eq,order,kw_only,frozen}_defaults of the dataclass-transformer, but all other standard-dataclass parameters should be equally supported with the same behavior.

Test Plan

Added regression tests.

@sharkdp sharkdp added ty Multi-file analysis & type inference ecosystem-analyzer labels Nov 15, 2025
@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 15, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 15, 2025

mypy_primer results

No ecosystem changes detected ✅

No memory usage changes detected ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 15, 2025

ecosystem-analyzer results

No diagnostic changes detected ✅
Full report with detailed diff (timing results)

@sharkdp sharkdp force-pushed the david/dataclass-transform-remaining-flags branch from 95aa333 to 3e52af4 Compare November 15, 2025 19:08
@sharkdp sharkdp marked this pull request as ready for review November 15, 2025 19:12
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thank you!

T = TypeVar("T", bound=type)

@dataclass_transform()
def fancy_model(*, slots: bool = False) -> Callable[[T], T]:
Copy link
Member

Choose a reason for hiding this comment

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

isn't slots=False the default default? Wouldn't a more interesting test be this?

Suggested change
def fancy_model(*, slots: bool = False) -> Callable[[T], T]:
def fancy_model(*, slots: bool = True) -> Callable[[T], T]:

(The same applies to your other examples below!)

Copy link
Contributor Author

@sharkdp sharkdp Nov 16, 2025

Choose a reason for hiding this comment

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

The default parameter here has no actual effect on anything. slots=False is the default behavior and there is no way to override this for a dataclass-transformer. There is no slots_default parameter for the dataclass_transform call.

For the parameters that can actually change their defaults (like kw_only), we already have tests elsewhere in this file. Here, we just test that we can also modify something like slots on an actual model/dataclass (not on the transformer / the template).

@sharkdp sharkdp force-pushed the david/dataclass-transform-remaining-flags branch from 3e52af4 to 528afe2 Compare November 16, 2025 09:42
@sharkdp sharkdp enabled auto-merge (squash) November 16, 2025 09:42
@sharkdp sharkdp merged commit dbd7248 into main Nov 16, 2025
40 checks passed
@sharkdp sharkdp deleted the david/dataclass-transform-remaining-flags branch November 16, 2025 09:46
dcreager added a commit that referenced this pull request Nov 17, 2025
* origin/main: (26 commits)
  Mention `force-exclude` in "Configuration > Python file discovery" (#21500)
  Avoid syntax error when formatting attribute expressions with outer parentheses, parenthesized value, and trailing comment on value (#20418)
  [ty] suppress invalid suggestions in import statements (#21484)
  Limit `eglot-format` hook to eglot-managed Python buffers (#21459)
  Adjust own-line comment placement between branches (#21185)
  [ty] Subscript assignment diagnostics follow-up (#21452)
  [ty] Inlay hint call argument location (#20349)
  [ty] Use `CompactStr` for `StringLiteralType` (#21497)
  Update CodSpeedHQ/action action to v4.3.4 (#21488)
  Update salsa digest to a885bb4 (#21486)
  Update dependency ruff to v0.14.5 (#21489)
  Update astral-sh/setup-uv action to v7.1.3 (#21487)
  Update Rust crate get-size2 to v0.7.2 (#21490)
  Update Rust crate indicatif to v0.18.3 (#21491)
  Update Rust crate quick-junit to v0.5.2 (#21492)
  Update taiki-e/install-action action to v2.62.52 (#21493)
  Fix analyze graph tests on windows (#21481)
  `analyze`: Add option to skip over imports in `TYPE_CHECKING` blocks (#21472)
  [ty] Dataclasses: `__hash__` semantics and `unsafe_hash` (#21470)
  [ty] Dataclass transform: complete set of parameters (#21474)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ecosystem-analyzer ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants