Skip to content

dataclasses: remove HasDataclassFields type parameter, use ClassVar#548

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

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

Conversation

@nstarman
Copy link
Contributor

@nstarman nstarman commented Feb 22, 2026

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
Copy link
Contributor

Copilot AI left a comment

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.

@jorenham
Copy link
Owner

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

@nstarman
Copy link
Contributor Author

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

@jorenham
Copy link
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
Owner

What's up with the unverified commits?

@nstarman
Copy link
Contributor Author

nstarman commented Feb 22, 2026

What's up with the unverified commits?

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

Copy link
Contributor

Copilot AI left a comment

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
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)

Co-authored-by: Joren Hammudoglu <jhammudoglu@gmail.com>
@nstarman
Copy link
Contributor Author

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

@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
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