Skip to content

Clarify generic type parameter ordering#2289

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

Clarify generic type parameter ordering#2289
BHUVANSH855 wants to merge 4 commits into
python:mainfrom
BHUVANSH855:spec/type-parameter-order

Conversation

@BHUVANSH855
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 srittau added the topic: typing spec For improving the typing spec label May 18, 2026
@JelleZijlstra
Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

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
@JelleZijlstra
Copy link
Copy Markdown
Member

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

@BHUVANSH855
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 BHUVANSH855 requested a review from JelleZijlstra May 21, 2026 14:45
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