You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pickling and repr of exceptions with kwargs #71202
3.10 (EOL)end of life3.11only security fixes3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2016-05-13.16:59:09.479>labels= ['type-bug', 'library', '3.9', '3.10', '3.11']
title='pickling and repr of exceptions with kwargs'updated_at=<Date2022-01-06.13:25:55.215>user='https://github.com/Taywee'
This is a problem not only with CalledProcessError, but with all custom exceptions with overridden __init__. BaseException.__new__ saves positional arguments as the "args" attribute, but ignores keyword arguments. repr() and pickle use "args".
remilapeyre commented on Jan 16, 2019
remilapeyremannequin
Mannequin
More actions
I tried to fix the issue, the attached PR solves the issue of saving the kwargs and unpickling the exception but I was not able to fix a regression I caused in test_memory_error_in_PyErr_PrintEx.
Reviewing Rémi's page made me realise that a big part of the root cause here is pickle support in exceptions predating the introduction of __getnewargs__ and __getnewargs_ex__.
3.10 (EOL)end of life3.11only security fixes3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
Activity
Taywee commentedon May 13, 2016
When using kwargs to construct a CalledProcessError, the repr doesn't show those args, and using kwargs also breaks pickling:
serhiy-storchaka commentedon May 13, 2016
This is a problem not only with CalledProcessError, but with all custom exceptions with overridden __init__. BaseException.__new__ saves positional arguments as the "args" attribute, but ignores keyword arguments. repr() and pickle use "args".
remilapeyre commentedon Jan 16, 2019
I tried to fix the issue, the attached PR solves the issue of saving the kwargs and unpickling the exception but I was not able to fix a regression I caused in test_memory_error_in_PyErr_PrintEx.
ncoghlan commentedon Jan 31, 2019
Reviewing Rémi's page made me realise that a big part of the root cause here is pickle support in exceptions predating the introduction of
__getnewargs__and__getnewargs_ex__.[-]subprocess.CalledProcessError's repr changes based on kwargs, and doesn't unpickle[/-]