Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Support options in functional dataclass calls#25989

Merged
charliermarsh merged 2 commits into
mainfrom
charlie/support-functional-dataclass-options
Jun 15, 2026
Merged

[ty] Support options in functional dataclass calls#25989
charliermarsh merged 2 commits into
mainfrom
charlie/support-functional-dataclass-options

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Jun 14, 2026

Copy link
Copy Markdown
Member

Summary

dataclass accepts the same keyword options when it is called directly with a class as when it is used as a decorator factory:

from dataclasses import dataclass

class Example:
    value: int

ordered = dataclass(Example, order=True)
ordered(1) < ordered(2)

Previously, our synthetic overloads only accepted these options when cls was omitted. Valid calls such as dataclass(Example, frozen=True) therefore produced no-matching-overload, and direct applications always used the default dataclass parameters.

This adds the keyword-only options to the direct-call overloads and reads dataclass arguments by parameter name, allowing the computed parameters to be applied consistently to decorator factories, explicit None calls, and direct class arguments.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Jun 14, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 14, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 94.36%. The percentage of expected errors that received a diagnostic held steady at 88.91%. The number of fully passing files held steady at 93/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 14, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Jun 14, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
no-matching-overload 0 2 0
Total 0 2 0

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Raw diff:

pydantic (https://github.com/pydantic/pydantic)
- pydantic/dataclasses.py:201:19 error[no-matching-overload] No overload of function `dataclass` matches arguments
- pydantic/v1/dataclasses.py:214:26 error[no-matching-overload] No overload of function `dataclass` matches arguments

Full report with detailed diff (timing results)

@charliermarsh charliermarsh force-pushed the charlie/support-functional-dataclass-options branch from fc5f2ce to baed917 Compare June 14, 2026 18:15
@charliermarsh charliermarsh added the bug Something isn't working label Jun 14, 2026
@charliermarsh charliermarsh marked this pull request as ready for review June 14, 2026 18:16
@charliermarsh charliermarsh marked this pull request as draft June 14, 2026 19:33
@charliermarsh charliermarsh force-pushed the charlie/support-functional-dataclass-options branch from 3cd00b0 to 3547eb5 Compare June 14, 2026 20:42
@codspeed-hq

codspeed-hq Bot commented Jun 14, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 71 untouched benchmarks
⏩ 60 skipped benchmarks1


Comparing charlie/support-functional-dataclass-options (f2aee5c) with main (cfa4d72)

Open in CodSpeed

Footnotes

  1. 60 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@charliermarsh charliermarsh force-pushed the charlie/support-functional-dataclass-options branch from 880de4d to b28c34a Compare June 14, 2026 23:24
@charliermarsh charliermarsh marked this pull request as ready for review June 14, 2026 23:25
Comment thread crates/ty_python_semantic/src/types.rs Outdated
Parameter::positional_only(Some(Name::new_static("cls")))
.with_annotated_type(cls_ty),
);
parameters.extend(decorator_factory_parameters.iter().cloned());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
parameters.extend(decorator_factory_parameters.iter().cloned());
parameters.extend_from_slice(&decorator_factory_parameters);

Comment on lines +2203 to +2205
.map_or((None, parameter_types), |(index, _)| {
(parameter_types[index], &parameter_types[index + 1..])
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same comment as #25985 (comment), I'd find this much more readable:

Suggested change
.map_or((None, parameter_types), |(index, _)| {
(parameter_types[index], &parameter_types[index + 1..])
});
.map(|(index, _)| {
(parameter_types[index], &parameter_types[index + 1..])
})
.unwrap_or((None, parameter_types));

@charliermarsh charliermarsh enabled auto-merge (squash) June 15, 2026 13:40
@charliermarsh charliermarsh merged commit c85951e into main Jun 15, 2026
59 checks passed
@charliermarsh charliermarsh deleted the charlie/support-functional-dataclass-options branch June 15, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants