Skip to content

Commit

Permalink
make exceptions copy- and pickleable
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl committed Oct 29, 2024
1 parent 1b0be05 commit b8d1fc7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'''
from __future__ import annotations

import copy
from functools import partial, wraps
import re
import ssl
Expand Down Expand Up @@ -1205,3 +1206,16 @@ async def server():
async with trio.open_nursery() as nursery:
nursery.start_soon(server)
nursery.start_soon(client)


def test_copy_exceptions():
# test that exceptions are copy- and pickleable
copy.copy(HandshakeError())
copy.copy(ConnectionTimeout())
copy.copy(DisconnectionTimeout())
assert copy.copy(ConnectionClosed("foo")).reason == "foo"

rej_copy = copy.copy(ConnectionRejected(404, (("a", "b"),), b"c"))
assert rej_copy.status_code == 404
assert rej_copy.headers == (("a", "b"),)
assert rej_copy.body == b"c"
4 changes: 2 additions & 2 deletions trio_websocket/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ def __init__(self, reason):
:param reason:
:type reason: CloseReason
'''
super().__init__()
super().__init__(reason)
self.reason = reason

def __repr__(self):
Expand All @@ -628,7 +628,7 @@ def __init__(self, status_code, headers, body):
:param reason:
:type reason: CloseReason
'''
super().__init__()
super().__init__(status_code, headers, body)
#: a 3 digit HTTP status code
self.status_code = status_code
#: a tuple of 2-tuples containing header key/value pairs
Expand Down

0 comments on commit b8d1fc7

Please sign in to comment.