Skip to content

Conversation

@thejchap
Copy link
Contributor

@thejchap thejchap commented Jul 25, 2025

Summary

astral-sh/ty#111

adds support for the new copy.replace and __replace__ protocol added in 3.13

Burndown

Test Plan

new mdtests

@github-actions
Copy link
Contributor

github-actions bot commented Jul 25, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@thejchap thejchap force-pushed the thejchap/more-dataclasses branch from 4cede2a to 168599f Compare July 25, 2025 01:53
@thejchap thejchap changed the title [ty] synthesize __replace__ for >=3.13 [ty] synthesize __replace__ for dataclasses (>=3.13) Jul 25, 2025
@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Jul 25, 2025
@AlexWaygood
Copy link
Member

Thank you for working on this!!

Hmm, I'm not sure we need to implement special casing for any of these. Typeshed should already include __replace__ methods for all of these in the stdlib stubs that we vendor, so no additional implementation from us should be required -- it should hopefully "just work"! I think the only cases where we need to add some special casing are named tuples and dataclasses, because for these very special types the methods are synthesized at runtime rather than being present in the source code.

@thejchap thejchap force-pushed the thejchap/more-dataclasses branch from 168599f to 9a743a2 Compare July 26, 2025 03:33
@thejchap thejchap marked this pull request as ready for review July 26, 2025 03:46
@thejchap
Copy link
Contributor Author

@AlexWaygood ready for some feedback on this one!

Copy link
Contributor

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

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

Very nice — thank you. I added a couple of minor inline comments.

@thejchap thejchap force-pushed the thejchap/more-dataclasses branch from 9a743a2 to 6ed4a25 Compare July 28, 2025 12:08
@github-actions
Copy link
Contributor

github-actions bot commented Jul 28, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@thejchap thejchap force-pushed the thejchap/more-dataclasses branch 2 times, most recently from 36d67e1 to e851706 Compare July 28, 2025 13:19
@thejchap
Copy link
Contributor Author

@sharkdp thanks! addressed most of your comments, and added a wip implementation of special handling of copy.replace here. please let me know if that's on the right track

if so, i'm fine to either merge as-is and complete that in a follow-on pr, or finish as part of this one

@thejchap thejchap force-pushed the thejchap/more-dataclasses branch from e851706 to 2861d0b Compare July 29, 2025 01:47
@thejchap thejchap force-pushed the thejchap/more-dataclasses branch 3 times, most recently from 6639db6 to 646685c Compare July 29, 2025 12:09
@thejchap thejchap force-pushed the thejchap/more-dataclasses branch from 646685c to e8a283a Compare July 29, 2025 12:10
@thejchap
Copy link
Contributor Author

@sharkdp thanks - i pulled out the invalid-argument-type logic for invalid replace(…) calls for now. i might work on this more in another pr

Copy link
Contributor

@sharkdp sharkdp 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 very much. I made a few minor adjustments.

@sharkdp sharkdp merged commit 656273b into astral-sh:main Jul 29, 2025
37 checks passed
dcreager added a commit that referenced this pull request Aug 1, 2025
* main: (24 commits)
  Add `Checker::context` method, deduplicate Unicode checks (#19609)
  [`flake8-pyi`] Preserve inline comment in ellipsis removal (`PYI013`) (#19399)
  [ty] Add flow diagram for import resolution
  [ty] Add comments to some core resolver functions
  [ty] Add missing ticks and use consistent quoting
  [ty] Reflow some long lines
  [ty] Unexport helper function
  [ty] Remove offset from `CompletionTargetTokens::Unknown`
  [`pyupgrade`] Fix `UP030` to avoid modifying double curly braces in format strings (#19378)
  [ty] fix a typo  (#19621)
  [ty] synthesize `__replace__` for dataclasses (>=3.13) (#19545)
  [ty] Discard `Definition`s when normalizing `Signature`s (#19615)
  [ty] Fix empty spans following a line terminator and unprintable character spans in diagnostics (#19535)
  Add `LinterContext::settings` to avoid passing separate settings (#19608)
  Support `.pyi` files in ruff analyze graph (#19611)
  [ty] Sync vendored typeshed stubs (#19607)
  [ty] Bump docstring-adder pin (#19606)
  [`perflint`] Ignore rule if target is `global` or `nonlocal` (`PERF401`) (#19539)
  Add license classifier back to pyproject.toml (#19599)
  [ty] Add stub mapping support to signature help (#19570)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants