Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f5dc1c4

Browse filesBrowse files
committed
Expand "invalid hash" test to assert normal StopIteration
Returning an explicit value from a generator function causes that value to be bound to the `value` attribute of the StopIteration exception. This is available as the result of "yield from" when it is used as an expression; or by explicitly catching StopIteration, binding the StopIteration exception to a variable, and accessing the attribute. This feature of generators is rarely used. The `return iter([])` statement in Submodule.iter_items uses this feature, causing the resulting StopIteration exception object to have a `value` attribute that refers to a separate second iterator that also yields no values (#1779). From context, this behavior is clearly not the goal; a bare return statement should be used here (which has the same effect except for the `value` attribute of the StopIteration exception). The code had used a bare return prior to 82b131c (#1282), when `return` was changed to `return iter([])`. That was part of a change that added numerous type annotations. It looks like it was either a mistake, or possibly an attempt to work around an old bug in a static type checker. This commit extends the test_iter_items_from_invalid_hash test to assert that the `value` attribute of the StopIteration is its usual default value of None. This commit only extends the test; it does not fix the bug.
1 parent 96fc354 commit f5dc1c4
Copy full SHA for f5dc1c4

File tree

1 file changed

+2
-1
lines changed
Filter options

1 file changed

+2
-1
lines changed

‎test/test_submodule.py

Copy file name to clipboardExpand all lines: test/test_submodule.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,9 @@ def test_iter_items_from_nonexistent_hash(self):
696696
def test_iter_items_from_invalid_hash(self):
697697
"""Check legacy behavaior on BadName (also applies to IOError, i.e. OSError)."""
698698
it = Submodule.iter_items(self.rorepo, "xyz")
699-
with self.assertRaises(StopIteration):
699+
with self.assertRaises(StopIteration) as ctx:
700700
next(it)
701+
self.assertIsNone(ctx.exception.value)
701702

702703
@with_rw_repo(k_no_subm_tag, bare=False)
703704
def test_first_submodule(self, rwrepo):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.