Skip to content

bpo-27015: Save kwargs given to exceptions constructor #11580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use __reduce_ex__ and __getnewargs_ex__
  • Loading branch information
Rémi Lapeyre committed Feb 21, 2019
commit 4657d7e06a334e7ceb9cffbd7139e1b403d3871a
29 changes: 17 additions & 12 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,16 +439,15 @@ def testAttributes(self):
value, expected[checkArgName]))

# test for pickling support
for p in [pickle]:
for protocol in range(p.HIGHEST_PROTOCOL + 1):
s = p.dumps(e, protocol)
new = p.loads(s)
for checkArgName in expected:
got = repr(getattr(new, checkArgName))
want = repr(expected[checkArgName])
self.assertEqual(got, want,
'pickled "%r", attribute "%s' %
(e, checkArgName))
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
s = pickle.dumps(e, protocol)
new = pickle.loads(s)
for checkArgName in expected:
got = repr(getattr(new, checkArgName))
want = repr(expected[checkArgName])
self.assertEqual(got, want,
'pickled "%r", attribute "%s"' %
(e, checkArgName))

def testWithTraceback(self):
try:
Expand Down Expand Up @@ -1417,8 +1416,14 @@ def test_pickle_overriden_init(self):
# Issue #27015
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
orig = NaiveException(x='foo')
exc = pickle.loads(pickle.dumps(orig, proto))
self.assertEqual(orig.x, exc.x)
if proto in (0, 1):
# Pickling excpetions keyword arguments is not supported for
# protocol 0 and 1
with self.assertRaises(TypeError):
pickle.loads(pickle.dumps(orig, proto))
else:
exc = pickle.loads(pickle.dumps(orig, proto))
self.assertEqual(orig.x, exc.x)


if __name__ == '__main__':
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy