Skip to content

Update generics reference to use PEP 695 type parameter syntax#2242

Open
BHUVANSH855 wants to merge 5 commits into
python:mainfrom
BHUVANSH855:update-generics-pep695
Open

Update generics reference to use PEP 695 type parameter syntax#2242
BHUVANSH855 wants to merge 5 commits into
python:mainfrom
BHUVANSH855:update-generics-pep695

Conversation

@BHUVANSH855

Copy link
Copy Markdown
Contributor

This PR updates the reference/generics.rst documentation to reflect the modern type parameter syntax introduced in PEP 695.

Changes include:

  • Updating initial examples (e.g., Stack, Box) to use class Foo[T] syntax
  • Adding a note explaining the transition from TypeVar/Generic to PEP 695
  • Retaining mention of older syntax for backward compatibility

This improves consistency with the spec documentation and reduces confusion for users of Python 3.12+.

Fixes #2227

Comment thread docs/reference/generics.rst
Comment thread docs/reference/generics.rst Outdated
@BHUVANSH855 BHUVANSH855 requested a review from srittau April 8, 2026 11:00
@srittau

srittau commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks so far, but I also think the whole "Defining subclasses of generic classes" needs to be rewritten, as with Python 3.12 syntax, Generic isn't used anymore.

@BHUVANSH855

BHUVANSH855 commented Apr 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks so far, but I also think the whole "Defining subclasses of generic classes" needs to be rewritten, as with Python 3.12 syntax, Generic isn't used anymore.

@srittau I made a few final refinements:

  • Updated wording of the note for clarity
  • Fully aligned subclassing examples with PEP 695 syntax
  • Removed outdated discussion of Generic

Everything should now consistently reflect the Python 3.12+ style.

Kindly review it again.

@BHUVANSH855

Copy link
Copy Markdown
Contributor Author

Hi @srittau @JelleZijlstra,

Just checking in regarding the latest updates to this PR.
Kindly let me know if any further changes are required.

Thank you!

Comment thread docs/reference/generics.rst Outdated
@BHUVANSH855

Copy link
Copy Markdown
Contributor Author

Hi @srittau @JelleZijlstra,

Just checking in regarding the latest updates to this PR.
Kindly let me know if any further changes are required.

Thank you!

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are lots of remaining places in the document using the old syntax. Look for all places that still use T = TypeVar("T")-style syntax and replace them.

Comment thread docs/reference/generics.rst Outdated
Comment thread docs/reference/generics.rst Outdated
Comment thread docs/reference/generics.rst Outdated
Comment thread docs/reference/generics.rst Outdated
@BHUVANSH855

Copy link
Copy Markdown
Contributor Author

Thanks for the review! @JelleZijlstra

I’ve now updated the generics reference to consistently use the PEP 695 type parameter syntax in all applicable examples, including generic functions, methods, class methods, and bounded type parameters.

I kept TypeVar usage only in sections where it is still required (such as variance, constraints, decorators, and ParamSpec), so the document stays accurate for those advanced cases.

Please let me know if anything else should be refined.

@BHUVANSH855

Copy link
Copy Markdown
Contributor Author

Hi @JelleZijlstra,

Just checking in regarding the latest updates to this PR.
Kindly let me know if any further changes are required.

Thank you!

@JelleZijlstra

Copy link
Copy Markdown
Member

The document still has many old-style ParamSpec and TypeVar declarations further down. It also says "By default, all user-defined generics are invariant." which is no longer correct.

@BHUVANSH855

Copy link
Copy Markdown
Contributor Author

The document still has many old-style ParamSpec and TypeVar declarations further down. It also says "By default, all user-defined generics are invariant." which is no longer correct.

Thanks for the review @JelleZijlstra,

I’ve updated the invariance statement and added the missing imports in the variance examples. I also ensured formatting consistency in the code blocks.

Please let me know if anything else needs adjustment.

@JelleZijlstra

Copy link
Copy Markdown
Member

Please stop pinging on this PR. I'm a bit tired of it because of the number of times I've had to ask you to complete the change. I'll look at it when I find the time and energy; in the meantime please do not send any more pings.

@BHUVANSH855 BHUVANSH855 force-pushed the update-generics-pep695 branch from cc96f6e to 9731d54 Compare May 16, 2026 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update reference/generics.html with PEP695 type parameter syntax

4 participants