GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-89547: Support for nesting special forms like Final by hmc-cs-mdrissi · Pull Request #116096 · python/cpython

Conversation

@hmc-cs-mdrissi

@hmc-cs-mdrissi hmc-cs-mdrissi commented Feb 29, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Resolves this issue. The main goal was to permit ClassVar[Final[int]] and Final[ClassVar[int]]. This drops validation check that Final/ClassVar argument is not a special form.

This does allow some silly cases like ClassVar[ClassVar[int]] but I think it's simpler to allow them then have more complex validation rules at runtime. I did not remove special form check for other forms so Union[ClassVar[int], int] remains forbidden and list[ClassVar[int]] is also forbidden. There already was a test case that list[ClassVar[int]] fails.

I also added couple tests for Annotated to ensure it can nest freely with ClassVar/Final.

  • Issue: Clarify meaning of Final in dataclasses #89547

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hmc-cs-mdrissi
Add support for nesting special forms like Final
a7ca1f7
@hmc-cs-mdrissi
hmc-cs-mdrissi requested review from AlexWaygood and JelleZijlstra as code owners February 29, 2024 04:11
@ghost

ghost commented Feb 29, 2024 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added the awaiting review label Feb 29, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Feb 29, 2024
Clarify meaning of Final in dataclasses #89547
Open
@Eclips4 Eclips4 added the topic-typing label Feb 29, 2024
AlexWaygood
AlexWaygood reviewed Feb 29, 2024
View reviewed changes

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Wow, that's an easy change to make! Not sure if we want to treat this as a new feature or a backportable bugfix — thoughts, @JelleZijlstra?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@hmc-cs-mdrissi
Add comment for special forms test
378aaea
JelleZijlstra
JelleZijlstra reviewed Mar 1, 2024
View reviewed changes

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks. I feel this should be treated as a new feature and not backported.

It's probably worth a versionchanged note in the typing docs, e.g. saying "ClassVar can now be nested inside Final".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@carljm

carljm commented Mar 1, 2024

Copy link
Copy Markdown
Member

@JelleZijlstra what do you see as the risk of backporting?

It seems like arguably a "bug" that (given the current de facto behavior of type checkers) there is no way to specify a Final, non-field, ClassVar, on a dataclass. Backporting this would fix that "bug" for all users of Python 3.11 and Python 3.12, rather than requiring they wait until 3.13.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra

JelleZijlstra commented Mar 1, 2024

Copy link
Copy Markdown
Member

It feels like a new feature to me; we're adding support for something that wasn't previously allowed. For example, if a library after the release of 3.12.3 starts using ClassVar[Final...] in its code and tests only on 3.12.3+, they would break all users who are still on 3.12.2 without realizing it.

Users on earlier versions can work around the problem by using quoted annotations.

carljm, AlexWaygood, and JWCS reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra
JelleZijlstra approved these changes Mar 12, 2024
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Mar 12, 2024
@JelleZijlstra
JelleZijlstra merged commit d308d33 into python:main Mar 12, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Mar 12, 2024
@AlexWaygood

AlexWaygood commented Mar 12, 2024

Copy link
Copy Markdown
Member

It's probably worth a versionchanged note in the typing docs, e.g. saying "ClassVar can now be nested inside Final".

This still needs to be done

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra JelleZijlstra mentioned this pull request Mar 12, 2024
gh-89547: typing.rst: Add note about change in behavior with ClassVar/Final #116686
Merged
@JelleZijlstra

JelleZijlstra commented Mar 12, 2024

Copy link
Copy Markdown
Member

Thanks, done in #116686

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
@hmc-cs-mdrissi @adorilson
pythongh-89547: Support for nesting special forms like Final (python#…
a9334b8
…116096)
@JWCS JWCS mentioned this pull request Mar 27, 2024
Allow Annotated to wrap Final and ClassVar python/mypy#12061
Open
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
@hmc-cs-mdrissi @diegorusso
pythongh-89547: Support for nesting special forms like Final (python#…
3381773
…116096)
@Viicos Viicos mentioned this pull request May 26, 2025
ClassVar[Final[T]] should be allowed microsoft/pyright#10500
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@AlexWaygood AlexWaygood AlexWaygood left review comments
@JelleZijlstra JelleZijlstra JelleZijlstra approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

topic-typing

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@hmc-cs-mdrissi @carljm @JelleZijlstra @AlexWaygood @Eclips4
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.