Skip to content

Type variable tuple variance#741

Open
KotlinIsland wants to merge 3 commits intopython:mainfrom
KotlinIsland:type-variable-tuple-variance
Open

Type variable tuple variance#741
KotlinIsland wants to merge 3 commits intopython:mainfrom
KotlinIsland:type-variable-tuple-variance

Conversation

@KotlinIsland
Copy link
Copy Markdown

@KotlinIsland KotlinIsland commented Apr 23, 2026

@KotlinIsland KotlinIsland force-pushed the type-variable-tuple-variance branch from e2e1470 to d686377 Compare April 23, 2026 04:04
Comment thread src/typing_extensions.py Outdated
@KotlinIsland KotlinIsland force-pushed the type-variable-tuple-variance branch 2 times, most recently from 58e8130 to aa22b98 Compare April 23, 2026 04:12
@KotlinIsland KotlinIsland force-pushed the type-variable-tuple-variance branch 3 times, most recently from 9f5c185 to 678c257 Compare April 23, 2026 04:19
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.

  • Can you also set tvt.__bound__ = bound for consistency?
  • Can you add tests and a changelog entry?

@KotlinIsland KotlinIsland force-pushed the type-variable-tuple-variance branch from 678c257 to 7d45019 Compare April 23, 2026 04:20
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 60.71429% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.72%. Comparing base (83caa59) to head (06fe0cc).

Files with missing lines Patch % Lines
src/typing_extensions.py 36.00% 16 Missing ⚠️
src/test_typing_extensions.py 80.64% 6 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (83caa59) and HEAD (06fe0cc). Click for more details.

HEAD has 12 uploads less than BASE
Flag BASE (83caa59) HEAD (06fe0cc)
3.10 1 0
3.13 1 0
3.12 1 0
3.11 1 0
3.14 1 0
pypy3.9 1 0
3.9.12 1 0
3.13.0 1 0
pypy3.11 1 0
3.9 1 0
pypy3.10 1 0
3.10.4 1 0
@@            Coverage Diff             @@
##             main     #741      +/-   ##
==========================================
- Coverage   97.38%   89.72%   -7.67%     
==========================================
  Files           3        3              
  Lines        7690     7738      +48     
==========================================
- Hits         7489     6943     -546     
- Misses        201      795     +594     
Flag Coverage Δ
3.10 ?
3.10.4 ?
3.11 ?
3.11.0 87.27% <60.71%> (-0.19%) ⬇️
3.12 ?
3.12.0 87.96% <60.71%> (-0.19%) ⬇️
3.13 ?
3.13.0 ?
3.14 ?
3.9 ?
3.9.12 ?
pypy3.10 ?
pypy3.11 ?
pypy3.9 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/test_typing_extensions.py 96.75% <80.64%> (-1.64%) ⬇️
src/typing_extensions.py 66.02% <36.00%> (-27.93%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/typing_extensions.py
def __init__(self, name, *, bound=None, covariant=False, contravariant=False,
infer_variance=False, default=NoDefault):
self.__name__ = name
self.__covariant__ = bool(covariant)
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.

Why does this branch call bool() on the variance-related arguments and _type_check on bound and the above one doesn't? We should have things behave the same way across versions.

self.assertEqual(repr(Ts_contra), '-Ts_contra')
self.assertEqual(repr(Ts_infer), 'Ts_infer')
else:
# Not worth creating our own version of TypeVarTuple
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.

I don't understand this comment, we do create our own version in order to add the variance arguments, so we might as well update the repr too.

In general the tests ideally shouldn't have version-dependent branches: it's a goal for typing-extensions for all versions to behave the same.

Comment thread CHANGELOG.md
Python 3.9. The `typing` implementation has always raised an error, and the
`typing_extensions` implementation has raised an error on Python 3.10+ since
`typing_extensions` v4.6.0. Patch by Brian Schubert.
- add `bound` and variance parameters to `TypeVarTuple`
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.

Suggested change
- add `bound` and variance parameters to `TypeVarTuple`
- Add `bound` and variance parameters to `TypeVarTuple`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants