GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||
GeezerVison is showing github.com — bpo-43224: Implement substitution of unpacked TypeVarTuple by serhiy-storchaka · Pull Request #31800 · python/cpython Conversation
|
| raise NotImplementedError( | ||
| "Type substitution for TypeVarTuples is not yet implemented" | ||
| ) | ||
| if len(self.__parameters__) == 1 and isinstance(self.__parameters__[0], TypeVarTuple): |
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
|
Thanks for looking into this! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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 I'd strongly prefer this merge to be reversed in favour of #31804 and/or further discussion on what the right approach is. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think that Workaround can be used in cases where this does not work. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.