Skip to content

gh-133956 fix bug where dataclass wouldn't detect ClassVar fields if ClassVar was re-exported from a module other than typing#140541

Open
taminomara wants to merge 6 commits intopython:mainfrom
taminomara:gh-133956-broken-classvar
Open

gh-133956 fix bug where dataclass wouldn't detect ClassVar fields if ClassVar was re-exported from a module other than typing#140541
taminomara wants to merge 6 commits intopython:mainfrom
taminomara:gh-133956-broken-classvar

Conversation

@taminomara
Copy link
Copy Markdown

@taminomara taminomara commented Oct 24, 2025

This PR continues work by @dzherb from #134073.

I've simplified the code and removed strict checks from _is_type. Supporting arbitrary levels of module nesting turned out to be beneficial for overall code complexity, so I've included it to this PR; I can send it as a separate PR with a separate issue, though.

Motivation for current implementation

I think we shouldn't assume anything about user-provided type annotations. All we know from annotation ty.ClassVar is that there is an object ty, and we're getting its attribute ClassVar. We shouldn't assume that ty is a module, nor that it doesn't implement some custom __getattr__ logic; instead, we should just do what the annotation tells us to do.

@python-cla-bot
Copy link
Copy Markdown

python-cla-bot bot commented Oct 24, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@taminomara taminomara force-pushed the gh-133956-broken-classvar branch from 5ecae28 to 2f64527 Compare October 24, 2025 12:29
@emcd
Copy link
Copy Markdown

emcd commented Nov 3, 2025

If someone is interested in confirming this works, writing tests, and putting up a PR, I'd be happy to review it.

@JelleZijlstra : In May, you said that you would be happy to review a PR which contains the fix and has tests. I believe that this PR meets those criteria. Would you review it?

@JelleZijlstra JelleZijlstra self-requested a review November 3, 2025 17:00
@taminomara
Copy link
Copy Markdown
Author

@JelleZijlstra are there any updates on this?

@emcd
Copy link
Copy Markdown

emcd commented Dec 25, 2025

@taminomara : You might also want to try pinging people in the issue thread too. They might ignore PRs if they do not have enough context.

Thank you for making this patch. I briefly glanced at it when you first made it a couple months ago and it looked like what I had in mind. Happy holidays!

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.

4 participants