FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Type variable tuple variance by KotlinIsland · Pull Request #741 · python/typing_extensions · GitHub

Type variable tuple variance - #741

Merged
JelleZijlstra merged 6 commits into
python:mainfrom
KotlinIsland:type-variable-tuple-variance
Jun 24, 2026
Merged

Type variable tuple variance#741
JelleZijlstra merged 6 commits into
python:mainfrom
KotlinIsland:type-variable-tuple-variance

Conversation

KotlinIsland commented Apr 23, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

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 force-pushed the type-variable-tuple-variance branch 2 times, most recently from 58e8130 to aa22b98 Compare April 23, 2026 04:12
KotlinIsland force-pushed the type-variable-tuple-variance branch 3 times, most recently from 9f5c185 to 678c257 Compare April 23, 2026 04:19

JelleZijlstra left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
  • Can you also set tvt.__bound__ = bound for consistency?
  • Can you add tests and a changelog entry?

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

codecov Bot commented Apr 23, 2026
edited
Loading

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.26%. Comparing base (0e05458) to head (8d0f70f).

@@            Coverage Diff             @@
##             main     #741      +/-   ##
==========================================
+ Coverage   97.19%   97.26%   +0.06%     
==========================================
  Files           3        3              
  Lines        7815     7862      +47     
==========================================
+ Hits         7596     7647      +51     
+ Misses        219      215       -4     
Flag Coverage Δ
3.10 88.85% <70.49%> (-0.09%) ⬇️
3.10.4 88.85% <70.49%> (-0.09%) ⬇️
3.11 88.03% <62.29%> (-0.16%) ⬇️
3.11.0 87.28% <62.29%> (-0.16%) ⬇️
3.12 87.97% <60.65%> (-0.16%) ⬇️
3.12.0 87.96% <60.65%> (-0.16%) ⬇️
3.13 83.39% <59.01%> (+0.45%) ⬆️
3.13.0 84.11% <59.01%> (+0.45%) ⬆️
3.14 79.54% <59.01%> (+0.49%) ⬆️
3.9 89.54% <70.49%> (-0.11%) ⬇️
3.9.12 89.54% <70.49%> (-0.11%) ⬇️
pypy3.10 88.69% <70.49%> (-0.09%) ⬇️
pypy3.11 87.89% <62.29%> (-0.16%) ⬇️
pypy3.9 89.37% <70.49%> (-0.11%) ⬇️

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 98.23% <100.00%> (+0.07%) ⬆️
src/typing_extensions.py 94.00% <100.00%> (+0.05%) ⬆️
🚀 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

KotlinIsland Apr 24, 2026
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

should _set_default also invoke _type_check?

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sorry I didn't come back here for a while. I think bool() is right for the boolean fields since it matches what we do for TypeVar. However, _type_check is actually wrong for ParamSpec and TypeVarTuple bounds, since it assumes a single type. This is actually a bug in CPython too, it rejects TypeVarTuple bounds like (int, str) that should be valid.

KotlinIsland Jun 22, 2026
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

it rejects TypeVarTuple bounds like (int, str) that should be valid.

is this in the spec? perhaps this is unrelated to this change

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ah right, we're not actually adding support for bounds here, only for variance. Might as well get this fixed in the runtime though.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Comment thread CHANGELOG.md Outdated
KotlinIsland force-pushed the type-variable-tuple-variance branch 3 times, most recently from cff0290 to 60d6c78 Compare April 24, 2026 02:28
KotlinIsland force-pushed the type-variable-tuple-variance branch from 60d6c78 to 550f1d1 Compare April 24, 2026 03:55
KotlinIsland force-pushed the type-variable-tuple-variance branch from 550f1d1 to 2a3a33b Compare June 14, 2026 15:56
Comment thread src/test_typing_extensions.py Outdated
Comment thread src/test_typing_extensions.py Outdated
JelleZijlstra merged commit 890be90 into python:main Jun 24, 2026
24 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

4 participants


Back | FazBrowse Home | New Git URL