Skip to content

dataclasses: remove HasDataclassFields type parameter, use ClassVar - #548

Merged
jorenham merged 8 commits into
jorenham:masterfrom
nstarman:patch-1
Feb 23, 2026
Merged

dataclasses: remove HasDataclassFields type parameter, use ClassVar#548
jorenham merged 8 commits into
jorenham:masterfrom
nstarman:patch-1

Conversation

@nstarman

@nstarman nstarman commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Removed unused imports and updated import statements for compatibility with Python versions.
@jorenham jorenham added this to the v0.17.0 milestone Feb 22, 2026
@nstarman
nstarman marked this pull request as ready for review February 22, 2026 18:35
@nstarman
nstarman requested a review from jorenham as a code owner February 22, 2026 18:35
Copilot AI review requested due to automatic review settings February 22, 2026 18:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the optype.dataclasses.HasDataclassFields runtime protocol to remove its generic type parameter and to model __dataclass_fields__ as a class attribute, aligning the protocol more closely with how dataclasses expose metadata.

Changes:

  • Deparametrized HasDataclassFields (removed TypeVar/Mapping-based generic parameter).
  • Marked HasDataclassFields.__dataclass_fields__ (and the test fake) as ClassVar[...].
  • Adjusted tests around isinstance/issubclass checks and added/updated type-checker ignores.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
optype/dataclasses.py Removes generic parameterization and makes __dataclass_fields__ a ClassVar on the protocol.
tests/test_dataclasses.py Updates test fixtures and assertions to match the new non-generic protocol shape.

Comment thread tests/test_dataclasses.py Outdated
Comment thread optype/dataclasses.py
@jorenham

Copy link
Copy Markdown
Owner

Looks like we've run into a pyrefly bug here. Do you want to report it or should I?

@nstarman

Copy link
Copy Markdown
Contributor Author

Go for it! I'm sure you've interacted with them more.

@jorenham

Copy link
Copy Markdown
Owner

It looks like it has already been raised: facebook/pyrefly#2477

@nstarman
nstarman requested a review from Copilot February 22, 2026 18:52
@jorenham

Copy link
Copy Markdown
Owner

What's up with the unverified commits?

@nstarman

nstarman commented Feb 22, 2026

Copy link
Copy Markdown
Contributor Author

What's up with the unverified commits?

GitHub Codespaces. Something isn't signed in correctly. Or something.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@jorenham

Copy link
Copy Markdown
Owner

What's up with the unverified commits?

GitHub Codespaces. Something isn't signed in correctly. Or something.

Hmm, should be possible https://docs.github.com/en/codespaces/managing-your-codespaces/managing-gpg-verification-for-github-codespaces (but you probably already know that)

Comment thread docs/reference/stdlib/dataclasses.md Outdated
Co-authored-by: Joren Hammudoglu <jhammudoglu@gmail.com>
@nstarman

Copy link
Copy Markdown
Contributor Author

Yeah, it's on my trusted repositories list for GPG signing.

Comment thread docs/reference/stdlib/dataclasses.md Outdated
@nstarman
nstarman requested a review from jorenham February 23, 2026 22:59
@jorenham jorenham changed the title Deparametrize HasDataclassFields and make attribute ClassVar dataclasses: remove HasDataclassFields type parameter, use ClassVar Feb 23, 2026
@jorenham
jorenham merged commit 7a42a73 into jorenham:master Feb 23, 2026
29 checks passed
@nstarman
nstarman deleted the patch-1 branch February 23, 2026 23:04
@jorenham

Copy link
Copy Markdown
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Protocol member DataclassInstance.__dataclass_fields__ expects class variable

3 participants