-
Notifications
You must be signed in to change notification settings - Fork 242
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
Fixed-size, multi-type sequence #592
Comments
I've seen this come up once in a while. These would primarily be useful for annotating legacy interfaces. Some observations:
Also, the class Iter:
def __iter__(self):
yield 1
yield "" The main objection to this feature I have is that it's pretty complicated to implement, and the use cases seem infrequent. Other extensions are probably higher priority. |
Thanks, I fixed the example. I agree that this is not high priority. |
This came up in python/typeshed#2287, but I have encountered the same problem myself. As far as I know, currently the only way to annotate a multi-type, fixed length sequence is using
Tuple
. But for input types this is often too strict:The implementations accept any iterable (first case) or sequence (second case) that yield two values:
It would be useful to have a way to annotate this. Of course type checkers would still need to reject generic cases like this:
But it could allow some things that are not possible at the moment, and opens the possibility for future improvements.
The text was updated successfully, but these errors were encountered: