python / python/cpython

[PEP 696] default substitution not applied correctly when parametrizing a generic type.

Open
#140,665 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

topic-typing type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

PEP 696 allows the default of a type-parameter to depend on other type parameters, however, this substitution is not applied at runtime:

class Bar[T, S=T]: ...

print(Bar[int])  # __main__.Bar[int, T]

The result should be __main__.Bar[int, int][^1]

This is likely the root cause for #140596. Tested with 3.13.8, 3.14.0 and 3.15.0a1+

[^1]: pyright playground, mypy-playground, ty-playground, pyrefly sandbox

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-151811

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PEP 696 section on using another type parameter as a default and reproduce the Bar[int] example from the report on CPython main. Compare the runtime generic alias with the expected main.Bar[int, int] result, and review linked PR gh-151811; done means the dependent default is substituted at runtime.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.