Skip to content

Commit b8d1fc7

Browse files
committed
make exceptions copy- and pickleable
1 parent 1b0be05 commit b8d1fc7

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

tests/test_connection.py

+14
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
'''
3232
from __future__ import annotations
3333

34+
import copy
3435
from functools import partial, wraps
3536
import re
3637
import ssl
@@ -1205,3 +1206,16 @@ async def server():
12051206
async with trio.open_nursery() as nursery:
12061207
nursery.start_soon(server)
12071208
nursery.start_soon(client)
1209+
1210+
1211+
def test_copy_exceptions():
1212+
# test that exceptions are copy- and pickleable
1213+
copy.copy(HandshakeError())
1214+
copy.copy(ConnectionTimeout())
1215+
copy.copy(DisconnectionTimeout())
1216+
assert copy.copy(ConnectionClosed("foo")).reason == "foo"
1217+
1218+
rej_copy = copy.copy(ConnectionRejected(404, (("a", "b"),), b"c"))
1219+
assert rej_copy.status_code == 404
1220+
assert rej_copy.headers == (("a", "b"),)
1221+
assert rej_copy.body == b"c"

trio_websocket/_impl.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ def __init__(self, reason):
608608
:param reason:
609609
:type reason: CloseReason
610610
'''
611-
super().__init__()
611+
super().__init__(reason)
612612
self.reason = reason
613613

614614
def __repr__(self):
@@ -628,7 +628,7 @@ def __init__(self, status_code, headers, body):
628628
:param reason:
629629
:type reason: CloseReason
630630
'''
631-
super().__init__()
631+
super().__init__(status_code, headers, body)
632632
#: a 3 digit HTTP status code
633633
self.status_code = status_code
634634
#: a tuple of 2-tuples containing header key/value pairs

0 commit comments

Comments
 (0)