Skip to content

Commit

Permalink
Fix: accidental removal of SuspensionError
Browse files Browse the repository at this point in the history
  • Loading branch information
s-cork committed Oct 7, 2021
1 parent 4a84e2c commit a8d0e15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ const pyExc = {

Object.assign(Sk.builtin, pyExc);


Sk.builtin.SuspensionError = simpleExtends(Exception, "SuspensionError", "Unsupported Suspension in code.");

Sk.builtin.ExternalError = Sk.abstr.buildNativeClass("ExternalError", {
constructor: function ExternalError(...args) {
this.nativeError = args[0];
Expand Down
16 changes: 16 additions & 0 deletions test/unit3/test_suspensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ def __contains__(self, key):
sleep(.01)
return bool(key)

class SleepingDunderFail:
# __iter__ can't suspend (__next__ can)
def __iter__(self):
sleep(0.01)
return iter([0, 1, 2])

class Test_Suspensions(unittest.TestCase):
def test_min_max(self):
x = [4, 1, 5]
Expand Down Expand Up @@ -71,6 +77,16 @@ def test_dunders(self):
# __contains__
self.assertFalse(0 in x)
self.assertTrue(1 in x)

def test_suspension_error(self):
x = SleepingDunderFail()
with self.assertRaises(Exception) as e:
for i in x:
pass
self.assertIn("Cannot call a function that blocks or suspends", str(e.exception))
self.assertTrue(repr(e.exception).startswith("SuspensionError"))



if __name__ == '__main__':
unittest.main()

0 comments on commit a8d0e15

Please sign in to comment.