-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix: #20341: [1.19 regression] [mypyc] generator → AssertionError #20371
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
Conversation
| assert items, "This function does not support empty tuples" | ||
| # Tuple might have elements of different types. | ||
| rtypes = {self.mapper.type_to_rtype(item) for item in target_type.items} | ||
| rtypes = set(map(self.mapper.type_to_rtype, items)) |
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 thought this looks more readable than the brackets when you're scanning quickly
| return self.get_sequence_type_from_type(target_type.upper_bound) | ||
| elif isinstance(target_type, TupleType): | ||
| items = target_type.items | ||
| assert items, "This function does not support empty tuples" |
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.
Not necessary but would have been marginally helpful
for more information, see https://pre-commit.ci
hauntsaninja
left a comment
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.
This looks reasonable to me, worth adding a test?
|
@BobTheBuidler Thank you for this PR! I confirm that it fixes #20341 From 1bb7a8edae97b976b28a02ea1d78862bca7fdc06 Mon Sep 17 00:00:00 2001
From: "Michael R. Crusoe" <[email protected]>
Date: Sun, 7 Dec 2025 11:03:23 +0100
Subject: [PATCH] added my reduced test case from the original issue
---
mypyc/test-data/run-generators.test | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/mypyc/test-data/run-generators.test b/mypyc/test-data/run-generators.test
index c8e831734..cf1dac7c5 100644
--- a/mypyc/test-data/run-generators.test
+++ b/mypyc/test-data/run-generators.test
@@ -936,3 +936,11 @@ def test_generator_override() -> None:
assert base1_foo(Base1()) == [1]
assert base1_foo(Derived1()) == [2, 3]
assert derived1_foo(Derived1()) == [2, 3]
+
+[case testGeneratorEmptyTuple]
+from collections.abc import Generator
+from typing import Optional, Union
+
+def test_compiledGeneratorEmptyTuple() -> None:
+ jobs: Generator[Optional[str], None, None] = (_ for _ in ())
+ assert list(jobs) == []
--
2.47.3 |
|
I've just added a test case now, and then I saw your message @mr-c . Thank you! @maintainers should I add his case in as well? |
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.
Yeah, I think worth adding mr-c's test. Don't think the test you added reproduces the issue
|
Added |
|
Thank you @BobTheBuidler @hauntsaninja ! |
This PR fixes #20341