Skip to content

Commit df6185d

Browse files
jacobtomlinsonionelmc
authored andcommitted
Handle optional OSError attributes
1 parent b197023 commit df6185d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/tblib/pickling_support.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ def pickle_exception(
7070
}
7171
args = ()
7272
if isinstance(obj, OSError):
73-
attrs.update(errno=obj.errno, strerror=obj.strerror)
73+
# Only set OSError-specific attributes if they are not None
74+
# Setting them to None explicitly breaks the string representation
75+
if obj.errno is not None:
76+
attrs['errno'] = obj.errno
77+
if obj.strerror is not None:
78+
attrs['strerror'] = obj.strerror
7479
if (winerror := getattr(obj, 'winerror', None)) is not None:
7580
attrs['winerror'] = winerror
7681
if obj.filename is not None:

0 commit comments

Comments
 (0)