-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for Concatenate with Ellipsis #442
Conversation
f518a15
to
dd275c0
Compare
100be12
to
7e0aac8
Compare
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.
Thanks for these fixes!
Please avoid force pushing for future changes; it makes it harder to track the history of the code. Instead, just push new commits to your branch, and we'll squash them when we merge the PR.
I've made a rework (moved the parts to |
src/test_typing_extensions.py
Outdated
@@ -5267,6 +5270,10 @@ class Y(Protocol[T, P]): | |||
self.assertEqual(G2.__args__, (int, Concatenate[int, P_2])) |
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.
Should the __args__
here be replaced by get_args
?
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.
fine to keep it as it is, realistically this attribute is never going away :)
src/test_typing_extensions.py
Outdated
@skipIf(TYPING_3_11_0, "Args can be non-types in 3.11+") | ||
def test_invalid_uses_before_3_11(self): | ||
P = ParamSpec('P') | ||
with self.assertRaisesRegex( | ||
TypeError, | ||
'each arg must be a type', | ||
): | ||
Concatenate[1, P] | ||
|
||
with self.assertRaisesRegex( | ||
TypeError, | ||
'each arg must be a type.', | ||
): | ||
Concatenate[1, ..., P] |
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 wonder if it's really worth adding this test? It seems like in later Python versions we decided that it was better to not raise exceptions in these cases, so that seems like the "desirable" behaviour, since we aim to reflect the behaviour in the latest version of the typing module as much as possible. That means that therefore the behaviour of raising exceptions on these in earlier Python versions is sort-of undesirable behaviour. I wouldn't see it as a big priority for us to fix it, but I'm also not sure it's necessary to have these assertions, if they're arguably asserting undesirable behaviour?
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.
Thank you for the reasoning and I do agree with you. The reasons why _type_check
was made more lax was to prevent bugs and have less restrictions to implement new features.
The only reason I see to keep at least the original test would be to test for a regression like forgetting to call _type_check
at all.
I would roll back the new test, it does not test something that is desirable to not pass. However, the reason to keep the other one around is not that strong. Would you prefer to keep it? In that case I'll add some comment to it.
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've changed the test to assure the _type_check
but with the currently undesired behavior.
Looks like you might have closed this accidentally. Probably this is something to do with the fact that it was a PR from your fork's |
Thanks for your kind reply. Yep I've just butchered this 🙈, I am sorry. It's as you assume related to the fork from |
We've all been there, pretty sure I've done it at least once :-) |
Fixes #110.
This PR adds support for Ellipsis in Concatenate for the Python 3.8-3.10 backports.
Does not fix:
Concatenate
implementation generates runtime exception if parameterized by...
#48 : Using Ellipsis as argument for Callable with a generic..typing.Callable
limitationstyping_extentions._ConcatenateGenericAlias
but also tricky.Changes:
_concatenate_getitem
to reflect the Python3.11 typing module that allows the Ellipsis parameter.typing._ConcatenateGenericAlias
and_concatenate_getitem
typing_extensions._ConcatenateGenericAlias
and_concatenate_getitem
like before