Skip to content

Fix type variable defaults depending on previous variables#21526

Merged
ilevkivskyi merged 2 commits into
python:masterfrom
ilevkivskyi:fix-tvd-on-prev
May 21, 2026
Merged

Fix type variable defaults depending on previous variables#21526
ilevkivskyi merged 2 commits into
python:masterfrom
ilevkivskyi:fix-tvd-on-prev

Conversation

@ilevkivskyi
Copy link
Copy Markdown
Member

@ilevkivskyi ilevkivskyi commented May 21, 2026

Fixes #19192
Fixes #20027
Fixes few TODOs in tests (don't know if there are relevant issues)
Closes #19382

Core idea is simple: don't do bizarre things :-) More precisely, instead of various in-place modifications (which is a big no-no for types), simply expand defaults iteratively as we build the environment for the type. Couple additional things:

  • Update defaults in freshen_function_type_vars() this is required for consistency when updating TypeVarIds.
  • Use fix_instance() in checkexpr.py for type applications. This will apply all type arguments in cases like x = Foo[int](...). The PEP and the spec say this is how it should be.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Copy Markdown
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks!

@ilevkivskyi ilevkivskyi merged commit 55ee0bd into python:master May 21, 2026
25 checks passed
@ilevkivskyi ilevkivskyi deleted the fix-tvd-on-prev branch May 21, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants