From 059066e81ae263663971f6a1bf7d476d8b89cc6a Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Wed, 12 Nov 2025 10:20:51 +0000 Subject: [PATCH] Handle optional OSError attributes --- src/tblib/pickling_support.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tblib/pickling_support.py b/src/tblib/pickling_support.py index 9dc6294..2f57449 100644 --- a/src/tblib/pickling_support.py +++ b/src/tblib/pickling_support.py @@ -70,7 +70,12 @@ def pickle_exception( } args = () if isinstance(obj, OSError): - attrs.update(errno=obj.errno, strerror=obj.strerror) + # Only set OSError-specific attributes if they are not None + # Setting them to None explicitly breaks the string representation + if obj.errno is not None: + attrs['errno'] = obj.errno + if obj.strerror is not None: + attrs['strerror'] = obj.strerror if (winerror := getattr(obj, 'winerror', None)) is not None: attrs['winerror'] = winerror if obj.filename is not None: