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 2 times, most recently from d686377 to 7ece722 Compare April 23, 2026 04:05
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 56.45161% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.45%. Comparing base (83caa59) to head (550f1d1).

Files with missing lines Patch % Lines
src/typing_extensions.py 27.58% 21 Missing ⚠️
src/test_typing_extensions.py 81.81% 6 Missing ⚠️

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

HEAD has 11 uploads less than BASE
Flag BASE (83caa59) HEAD (550f1d1)
3.10 1 0
3.12 1 0
3.11 1 0
pypy3.9 1 0
3.9.12 1 0
pypy3.11 1 0
3.9 1 0
3.12.0 1 0
pypy3.10 1 0
3.10.4 1 0
3.11.0 1 0
@@             Coverage Diff             @@
##             main     #741       +/-   ##
===========================================
- Coverage   97.38%   83.45%   -13.94%     
===========================================
  Files           3        3               
  Lines        7690     7741       +51     
===========================================
- Hits         7489     6460     -1029     
- Misses        201     1281     +1080     
Flag Coverage Δ
3.10 ?
3.10.4 ?
3.11 ?
3.11.0 ?
3.12 ?
3.12.0 ?
3.13 82.09% <56.45%> (+0.43%) ⬆️
3.13.0 82.81% <56.45%> (+0.42%) ⬆️
3.14 78.56% <56.45%> (+0.46%) ⬆️
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 95.87% <81.81%> (-2.53%) ⬇️
src/typing_extensions.py 41.62% <27.58%> (-52.33%) ⬇️
🚀 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.

Copy link
Copy Markdown
Author

@KotlinIsland KotlinIsland Apr 24, 2026

Choose a reason for hiding this comment

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

the implementation of ParamSpec also has this discrepancy, i will update it accordingly

should _set_default also invoke _type_check?

Comment thread src/test_typing_extensions.py Outdated
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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

it's adapted from the ParamSpec test which does similar. we do create a class for TypeVarTuple, but it doesn't return Self, so we can't update the repr

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

# On other versions we use typing.ParamSpec, but it is not aware of

Comment thread CHANGELOG.md Outdated
@KotlinIsland KotlinIsland force-pushed the type-variable-tuple-variance branch 3 times, most recently from cff0290 to 60d6c78 Compare April 24, 2026 02:28
@KotlinIsland KotlinIsland force-pushed the type-variable-tuple-variance branch from 60d6c78 to 550f1d1 Compare April 24, 2026 03: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

Development

Successfully merging this pull request may close these issues.

2 participants