Skip to content

Conversation

abhijeetbodas2001
Copy link
Contributor

@abhijeetbodas2001 abhijeetbodas2001 commented Jun 14, 2025

Summary

Add support for dataclasses.KW_ONLY as specified in https://docs.python.org/3/library/dataclasses.html#dataclasses.KW_ONLY

Part of astral-sh/ty#111

Test Plan

More mdtests.

Copy link
Contributor

github-actions bot commented Jun 14, 2025

mypy_primer results

No ecosystem changes detected ✅

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Jun 14, 2025
@abhijeetbodas2001
Copy link
Contributor Author

There's one TODO here for detecting more than one field annotated with KW_ONLY (and then emitting a diagnostic for that, since the spec says that's not allowed), which I'm yet to figure out how to setup.

But the main functionality is now working, so I'd appreciate a review on it. But please also see the question at the end of astral-sh/ty#111 (comment)

@abhijeetbodas2001 abhijeetbodas2001 marked this pull request as ready for review June 16, 2025 06:52
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.

Thanks, this is great!

@AlexWaygood AlexWaygood enabled auto-merge (squash) June 16, 2025 17:23
@AlexWaygood AlexWaygood merged commit 2b15f1d into astral-sh:main Jun 16, 2025
32 checks passed
@@ -600,11 +600,6 @@ impl<'db> Type<'db> {
.is_some_and(|instance| instance.class.is_known(db, KnownClass::NotImplementedType))
}

pub fn is_dataclass_kw_only(&self, db: &'db dyn Db) -> bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you prefer not having a function since there's only one caller?

Copy link
Member

Choose a reason for hiding this comment

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

yep. If we find other places in the codebase that need this in the future, I think we could consider adding a Type method, but for now it seems likely to me that the places we'll need this information are quite localised to one specific area of the codebase :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, that makes sense, thanks!

dcreager added a commit that referenced this pull request Jun 16, 2025
* main: (38 commits)
  [`pyupgrade`] Suppress `UP008` diagnostic if `super` symbol is not builtin (#18688)
  [pylint] Fix `PLW0128` to check assignment targets in square brackets and after asterisks (#18665)
  [`refurb`] Make the fix for `FURB163` unsafe for `log2`, `log10`, `*args`, and deleted comments (#18645)
  [ty] allow `T: Never` as subtype of `Never` (#18687)
  [ty] Use more parallelism when running corpus tests (#18711)
  [ty] Support `dataclasses.KW_ONLY` (#18677)
  [`ruff`] Check for non-context-manager use of `pytest.raises`, `pytest.warns`, and `pytest.deprecated_call` (`RUF061`) (#17368)
  Add syntax error when conversion flag does not immediately follow exclamation mark (#18706)
  [`flake8-pyi`] Fix `custom-typevar-for-self` with string annotations (`PYI019`) (#18311)
  Drop confusing second `*` from glob pattern example (#18709)
  [ty] Stabilize completions (#18650)
  [ty] Correctly label typeshed-sync PRs (#18702)
  Update Rust crate memchr to v2.7.5 (#18696)
  Update dependency react-resizable-panels to v3.0.3 (#18691)
  Update Rust crate clap to v4.5.40 (#18692)
  Update Rust crate libcst to v1.8.2 (#18695)
  Update Rust crate jiff to v0.2.15 (#18693)
  Update Rust crate libc to v0.2.173 (#18694)
  Update Rust crate syn to v2.0.103 (#18698)
  Update Rust crate toml to v0.8.23 (#18699)
  ...
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.

2 participants