FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Clarify generic type parameter ordering by BHUVANSH855 · Pull Request #2289 · python/typing · GitHub

Repository navigation

Clarify generic type parameter ordering - #2289

Open
BHUVANSH855 wants to merge 4 commits into
python:mainfrom
BHUVANSH855:spec/type-parameter-order
Open

BHUVANSH855 wants to merge 4 commits into
python:mainfrom
BHUVANSH855:spec/type-parameter-order

Conversation

Copy link
Copy Markdown
Contributor

Summary

Clarify how type parameter ordering is determined for generic classes.

This expands the existing wording in the generics spec to explicitly
cover:

  • Generic[...] base classes
  • parameterized Protocol[...] base classes
  • Python 3.12 generic class syntax

The updated wording also clarifies that a bare Protocol base class
does not affect type parameter ordering.

Closes #2059

srittau added the topic: typing spec For improving the typing spec label May 18, 2026

Copy link
Copy Markdown
Member

@BHUVANSH855 please do not keep merging main into your branch unless there is an actual merge conflict.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think we should add a section header "Type parameter ordering", starting at line 487 or so. Currently this is in a section "Arbitrary generic types as base classes", which isn't really apposite.

Comment thread docs/spec/generics.rst Outdated
Comment thread docs/spec/generics.rst Outdated

Copy link
Copy Markdown
Member

Also, is this already covered sufficiently in the conformance suite? What are the relevant tests that we have?

Copy link
Copy Markdown
Contributor Author

Also, is this already covered sufficiently in the conformance suite? What are the relevant tests that we have?

Addressed the requested changes:

  • added a dedicated “Type parameter ordering” section header
  • reordered the section so the Python 3.12 generic class syntax appears first
  • updated “both examples” to “all of the examples above”

There is already conformance coverage for Protocol[...] ordering in conformance/tests/protocols_generic.py. In particular, the Proto1(Iterable[T_co], Protocol[S, T_co]) example together with the specialization checks verifies that type parameter ordering follows the Protocol[...] subscript order.

This PR expands the spec wording to make the broader ordering rules explicit, including Generic[...], parameterized Protocol[...], bare Protocol, and PEP 695 syntax.

BHUVANSH855 requested a review from JelleZijlstra May 21, 2026 14:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: typing spec For improving the typing spec

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spec: More precision on type parameter order

3 participants


Back | FazBrowse Home | New Git URL