Skip to content

Conversation

leandrobbraga
Copy link
Contributor

This commit corrects the type checker's behavior when handling dataclass_transform decorators that don't explicitly specify field_specifiers. According to PEP 681 (Data Class Transforms), when field_specifiers is not provided, it defaults to an empty tuple, meaning no field specifiers are supported and dataclasses.field/dataclasses.Field calls should be ignored.

Fixes astral-sh/ty#980

Copy link
Contributor

github-actions bot commented Aug 20, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

Copy link
Contributor

github-actions bot commented Aug 20, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@AlexWaygood AlexWaygood added ty Multi-file analysis & type inference bug Something isn't working labels Aug 20, 2025
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

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

This looks good to me, thank you!

Clearly when we add full field_specifiers support, we will probably replace/remove this simple boolean flag. But this improves the current behavior, and doesn't make the future changes more difficult.

@sharkdp are you okay with this temporary fix?

@carljm
Copy link
Contributor

carljm commented Aug 20, 2025

Going to go ahead and merge this, it's a small PR, there's nothing here that we can't easily change again.

Thank you for the fix!

@carljm carljm merged commit 39ee71c into astral-sh:main Aug 20, 2025
38 checks passed
@sharkdp
Copy link
Contributor

sharkdp commented Aug 20, 2025

@sharkdp are you okay with this temporary fix?

Yes, of course. Thank you for this contribution!

dcreager added a commit that referenced this pull request Aug 21, 2025
* main: (29 commits)
  [ty] add docstrings to completions based on type (#20008)
  [`pyupgrade`] Avoid reporting `__future__` features as unnecessary when they are used (`UP010`) (#19769)
  [`flake8-use-pathlib`] Add fixes for `PTH102` and `PTH103` (#19514)
  [ty] correctly ignore field specifiers when not specified (#20002)
  `Option::unwrap` is now const (#20007)
  [ty] Re-arrange "list modules" implementation for Salsa caching
  [ty] Test "list modules" versus "resolve module" in every mdtest
  [ty] Wire up "list modules" API to make module completions work
  [ty] Tweak some completion tests
  [ty] Add "list modules" implementation
  [ty] Lightly expose `FileModule` and `NamespacePackage` fields
  [ty] Add some more helper routines to `ModulePath`
  [ty] Fix a bug when converting `ModulePath` to `ModuleName`
  [ty] Split out another constructor for `ModuleName`
  [ty] Add stub-file tests to existing module resolver
  [ty] Expose some routines in the module resolver
  [ty] Add more path helper functions
  [`flake8-annotations`] Remove unused import in example (`ANN401`) (#20000)
  [ty] distinguish base conda from child conda (#19990)
  [ty] Fix server hang (#19991)
  ...
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.

ty wrongly respects dataclasses.field as a field specifier for a custom dataclass_transform
4 participants