(self)
| 1089 | |
| 1090 | @unittest.expectedFailure # TODO: RUSTPYTHON |
| 1091 | def test_yield(self): |
| 1092 | # Allowed as standalone statement |
| 1093 | def g(): yield 1 |
| 1094 | def g(): yield from () |
| 1095 | # Allowed as RHS of assignment |
| 1096 | def g(): x = yield 1 |
| 1097 | def g(): x = yield from () |
| 1098 | # Ordinary yield accepts implicit tuples |
| 1099 | def g(): yield 1, 1 |
| 1100 | def g(): x = yield 1, 1 |
| 1101 | # 'yield from' does not |
| 1102 | check_syntax_error(self, "def g(): yield from (), 1") |
| 1103 | check_syntax_error(self, "def g(): x = yield from (), 1") |
| 1104 | # Requires parentheses as subexpression |
| 1105 | def g(): 1, (yield 1) |
| 1106 | def g(): 1, (yield from ()) |
| 1107 | check_syntax_error(self, "def g(): 1, yield 1") |
| 1108 | check_syntax_error(self, "def g(): 1, yield from ()") |
| 1109 | # Requires parentheses as call argument |
| 1110 | def g(): f((yield 1)) |
| 1111 | def g(): f((yield 1), 1) |
| 1112 | def g(): f((yield from ())) |
| 1113 | def g(): f((yield from ()), 1) |
| 1114 | # Do not require parenthesis for tuple unpacking |
| 1115 | def g(): rest = 4, 5, 6; yield 1, 2, 3, *rest |
| 1116 | self.assertEqual(list(g()), [(1, 2, 3, 4, 5, 6)]) |
| 1117 | check_syntax_error(self, "def g(): f(yield 1)") |
| 1118 | check_syntax_error(self, "def g(): f(yield 1, 1)") |
| 1119 | check_syntax_error(self, "def g(): f(yield from ())") |
| 1120 | check_syntax_error(self, "def g(): f(yield from (), 1)") |
| 1121 | # Not allowed at top level |
| 1122 | check_syntax_error(self, "yield") |
| 1123 | check_syntax_error(self, "yield from") |
| 1124 | # Not allowed at class scope |
| 1125 | check_syntax_error(self, "class foo:yield 1") |
| 1126 | check_syntax_error(self, "class foo:yield from ()") |
| 1127 | # Check annotation refleak on SyntaxError |
| 1128 | check_syntax_error(self, "def g(a:(yield)): pass") |
| 1129 | |
| 1130 | @unittest.expectedFailure # TODO: RUSTPYTHON |
| 1131 | def test_yield_in_comprehensions(self): |
nothing calls this directly
no test coverage detected