GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-43224: Implement substitution of unpacked TypeVarTuple by serhiy-storchaka · Pull Request #31800 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Mar 10, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

https://bugs.python.org/issue43224

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka
serhiy-storchaka requested review from Fidget-Spinner, JelleZijlstra and gvanrossum as code owners March 10, 2022 18:54
@bedevere-bot bedevere-bot added the awaiting core review label Mar 10, 2022
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Mar 10, 2022
@serhiy-storchaka
bpo-43224: Implement substitution of unpacked TypeVarTuple
4fab260
@serhiy-storchaka
serhiy-storchaka force-pushed the typevartuple-subst branch from da60f24 to 4fab260 Compare March 10, 2022 18:55
mrahtz
mrahtz reviewed Mar 10, 2022
View reviewed changes
Comment thread Lib/typing.py Outdated
raise NotImplementedError(
"Type substitution for TypeVarTuples is not yet implemented"
)
if len(self.__parameters__) == 1 and isinstance(self.__parameters__[0], TypeVarTuple):

@mrahtz mrahtz Mar 10, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'm not sure it's sufficient to only check for the case where len(self.__parameters__) == 1 - we could have e.g.:

T1 = TypeVar('T1')
T2 = TypeVar('T2')
Ts = TypeVarTuple('Ts')
class A(Generic[T1, T2, Unpack[Ts]]): pass
B = A[int, T2, Unpack[Ts]]
C = B[str, float]
print(C)

There, B.__parameters__ is (T2, Ts), causing a TypeError later on in the code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@serhiy-storchaka serhiy-storchaka Mar 11, 2022

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You are right. The previous code only worked with existing tests. New code adds tests for generics with multiple type variables.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mrahtz

mrahtz commented Mar 10, 2022

Copy link
Copy Markdown
Contributor

Thanks for looking into this!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Mar 10, 2022
bpo-43224: Implement PEP 646 changes to typing.py #31021
Merged
bpo-43224: Work around substitution of unpacked TypeVarTuple #31804
Closed
serhiy-storchaka added 4 commits March 11, 2022 09:53
@serhiy-storchaka
Support multiple type variables
8a8cf5d
@serhiy-storchaka
Add tests for Tuple.
a376210
@serhiy-storchaka
Merge branch 'main' into typevartuple-subst
b0412ec
@serhiy-storchaka
Simplify.
425d779
@serhiy-storchaka serhiy-storchaka added the skip news label Mar 11, 2022
@serhiy-storchaka
serhiy-storchaka merged commit 5b1b9ea into python:main Mar 11, 2022
@bedevere-bot bedevere-bot removed the awaiting core review label Mar 11, 2022
@serhiy-storchaka
serhiy-storchaka deleted the typevartuple-subst branch March 11, 2022 19:44
@JelleZijlstra JelleZijlstra mentioned this pull request Mar 11, 2022
bpo-43224: Implement substitution of unpacked TypeVarTuple in C #31828
Merged
@mrahtz

mrahtz commented Mar 12, 2022

Copy link
Copy Markdown
Contributor

Woah, I'm not sure merging this was a good idea. We discussed this extensively in #31021 (review) and decided against implementing it this way. There are too many edge cases (e.g. the merged implementation will happily assign an unpacked arbitrary-length tuple such as *tuple[int, ...] to a plain TypeVar, which is not legal - see the extensive tests in b9b1c80#diff-04d29c98076c2d6bb75921ea9becb26a862544d39b71db87b6e354c759b9305dL794), and @JelleZijlstra suspected it might cause issues with Annotated.

I'd strongly prefer this merge to be reversed in favour of #31804 and/or further discussion on what the right approach is.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Mar 12, 2022

Copy link
Copy Markdown
Member Author

I think that list[T][int] should return list[int], and tuple[*Ts][int, str] should return tuple[int, str].

Workaround can be used in cases where this does not work.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mrahtz

mrahtz commented Mar 13, 2022

Copy link
Copy Markdown
Contributor

If you're adamant about keeping this implementation, I don't feel happy about it, but I don't want this to become a blocker for us. I'll submit a new PR with extra test cases so we can be more confident we've covered the edge cases.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mrahtz mrahtz mentioned this pull request Mar 13, 2022
bpo-43224: Add more tests for typevar substitution #31844
Closed
@mrahtz mrahtz mannequin mentioned this pull request Apr 11, 2022
Add support for PEP 646 #87390
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gvanrossum gvanrossum Awaiting requested review from gvanrossum
@Fidget-Spinner Fidget-Spinner Awaiting requested review from Fidget-Spinner
@JelleZijlstra JelleZijlstra Awaiting requested review from JelleZijlstra JelleZijlstra is a code owner
1 more reviewer
@mrahtz mrahtz mrahtz left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@serhiy-storchaka @mrahtz @the-knights-who-say-ni @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.