Title: Spec: More precision on type parameter order · Issue #2059 · python/typing · GitHub
Open Graph Title: Spec: More precision on type parameter order · Issue #2059 · python/typing
X Title: Spec: More precision on type parameter order · Issue #2059 · python/typing
Description: The spec currently isn't very precise on the order in which type parameters appear in a class. (Given a class C that is generic over type parameters T1 and T2, does C[int, str] mean that T1 is bound to int or that T2 is bound to int?) I ...
Open Graph Description: The spec currently isn't very precise on the order in which type parameters appear in a class. (Given a class C that is generic over type parameters T1 and T2, does C[int, str] mean that T1 is boun...
X Description: The spec currently isn't very precise on the order in which type parameters appear in a class. (Given a class C that is generic over type parameters T1 and T2, does C[int, str] mean that T1 is ...
Opengraph URL: https://github.com/python/typing/issues/2059
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Spec: More precision on type parameter order","articleBody":"The spec currently isn't very precise on the order in which type parameters appear in a class. (Given a class C that is generic over type parameters T1 and T2, does `C[int, str]` mean that T1 is bound to int or that T2 is bound to int?)\n\nI think the rule should be:\n\n- If PEP 695 syntax is used, the order is the order in which the type parameters appear in the type parameter list.\n- If the class has `Generic[...]` as a syntactic base, the order is the order of the type arguments to `Generic`.\n- If the class has `Protocol[...]` as a syntactic base, the order is the order of the type arguments to `Protocol`. This applies only if Protocol is subscripted, not if the class inherits from bare `Protocol`.\n- Otherwise, the order is the order in which the type parameters appear syntactically in the base class list.\n\nAs far as I know, this is how all type checkers currently behave, but we just found out it's not how the runtime behaves when Protocol is involved: https://github.com/python/cpython/issues/137191#issuecomment-3132748382.\n\nIn these examples, all classes are generic over two parameters T1 and T2, and in all cases the type parameter order is T1, T2:\n\n```python\nfrom typing import Generic, Protocol, TypeVar\n\nclass C1[T1, T2]: ... # order is T1, T2\n\nT1 = TypeVar(\"T1\")\nT2 = TypeVar(\"T2\")\n\nclass C2(C1[T2, T1], Generic[T1, T2]): ... # order is T1, T2\n\nclass GenericProto[T1, T2](Protocol): ... # order is T1, T2\n\nclass Proto2(GenericProto[T2, T1], Protocol[T1, T2]): ... # order is T1, T2\n\nclass Proto3(GenericProto[T1, T2], Protocol): ... # order is T1, T2\n\nclass C3(C2[T1, T2]): ... # order is T1, T2\n```\n\nWe should change the spec to make this rule explicit. The only current rule appears to be in https://typing.python.org/en/latest/spec/generics.html#arbitrary-generic-types-as-base-classes \"Type variables are applied to the defined class in the order in which they first appear in any generic base classes\".","author":{"url":"https://github.com/JelleZijlstra","@type":"Person","name":"JelleZijlstra"},"datePublished":"2025-07-29T14:27:36Z","url":"https://github.com/python/typing/issues/2059"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a616ee6f-004a-c45a-c4b3-c5df20d0ebcb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 89F6:360F0F:2BF448:3936AC:6AFF8612 |
| html-safe-nonce | 3c1077f9755afd030f005c616a5639a6d7bcaae1329b006873046705cf5f09cc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OUY2OjM2MEYwRjoyQkY0NDg6MzkzNkFDOjZBRkY4NjEyIiwidmlzaXRvcl9pZCI6IjEyNjM3NjU2ODMwNzQ3Mjk0OTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | eb1be5152e28fd98c7b670f4348ea9eda2d9a3b3ec9698bfceb8328b045eea89 |
| hovercard-subject-tag | issue:3273873471 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/typing/2059/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5084333123480cbff6fcf6d81a159943645ce618f8e21f856bf49a9f7d933ddf/python/typing/issues/2059 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5084333123480cbff6fcf6d81a159943645ce618f8e21f856bf49a9f7d933ddf/python/typing/issues/2059 |
| og:image:alt | The spec currently isn't very precise on the order in which type parameters appear in a class. (Given a class C that is generic over type parameters T1 and T2, does C[int, str] mean that T1 is boun... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JelleZijlstra |
| hostname | github.com |
| expected-hostname | github.com |
| None | 19488db4031f00b04ea79b4c70b5dd32cfa873a8d20b3877f3896b8e2d195946 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7952f5285f4ba685d70c4c7540ad3cc9dc9746b8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width