Skip to content

Conversation

@BobTheBuidler
Copy link
Contributor

@BobTheBuidler BobTheBuidler commented Dec 6, 2025

This PR fixes #20341

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))
Copy link
Contributor Author

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"
Copy link
Contributor Author

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

@BobTheBuidler BobTheBuidler marked this pull request as ready for review December 6, 2025 20:52
@BobTheBuidler BobTheBuidler changed the title fix: mypyc#20341 fix: #20341 Dec 6, 2025
@BobTheBuidler BobTheBuidler changed the title fix: #20341 fix: #20341: [1.19 regression] [mypyc] generator → AssertionError Dec 6, 2025
Copy link
Collaborator

@hauntsaninja hauntsaninja left a 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?

@mr-c
Copy link
Contributor

mr-c commented Dec 7, 2025

@BobTheBuidler Thank you for this PR! I confirm that it fixes #20341
Here's a patch to add the test case from the original issue, which correctly fails without your fix.

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

@BobTheBuidler
Copy link
Contributor Author

BobTheBuidler commented Dec 8, 2025

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?

Copy link
Collaborator

@hauntsaninja hauntsaninja left a 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

@BobTheBuidler
Copy link
Contributor Author

Added

@hauntsaninja hauntsaninja merged commit 488f3c7 into python:master Dec 9, 2025
16 checks passed
@mr-c mr-c mentioned this pull request Dec 9, 2025
@mr-c
Copy link
Contributor

mr-c commented Dec 9, 2025

Thank you @BobTheBuidler @hauntsaninja !

@BobTheBuidler BobTheBuidler deleted the patch-27 branch December 9, 2025 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[1.19 regression] [mypyc] generator → AssertionError

3 participants