Skip to content

Commit abec37d

Browse files
committed
Update changelog and add one more test.
1 parent 12c8770 commit abec37d

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

CHANGELOG.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22
Changelog
33
=========
44

5+
3.2.0 (2025-10-21)
6+
~~~~~~~~~~~~~~~~~~
7+
8+
* Changed ``tblib.pickling_support.install`` to support exceptions with ``__init__`` that does match the default
9+
``BaseException.__reduce__`` (as it expects the positional arguments to ``__init__`` to match the ``args`` attribute).
10+
11+
Special handling for OSError (and subclasses) is also included. The errno, strerror, winerror, filename and filename2 attributes will be added in the reduce structure (if set).
12+
13+
This will support exception subclasses that do this without defining a custom ``__reduce__``:
14+
15+
.. code-block:: python
16+
17+
def __init__(self):
18+
super().__init__('mistery argument')
19+
20+
def __init__(self, mistery_argument):
21+
super().__init__()
22+
self.mistery_argument = mistery_argument
23+
24+
525
3.1.0 (2025-03-31)
626
~~~~~~~~~~~~~~~~~~
727

tests/test_pickle_exception.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,27 @@ def test_baderror():
279279
assert exc.__traceback__ is not None
280280

281281

282+
class BadError2(Exception):
283+
def __init__(self, stuff):
284+
super().__init__()
285+
self.stuff = stuff
286+
287+
288+
def test_baderror2():
289+
try:
290+
raise BadError2('123')
291+
except Exception as e:
292+
exc = e
293+
294+
tblib.pickling_support.install(exc)
295+
exc = pickle.loads(pickle.dumps(exc))
296+
297+
assert isinstance(exc, BadError2)
298+
assert exc.args == ()
299+
assert exc.stuff == '123'
300+
assert exc.__traceback__ is not None
301+
302+
282303
class CustomReduceException(Exception):
283304
def __init__(self, message, arg1, arg2, arg3):
284305
super().__init__(message)

0 commit comments

Comments
 (0)