diff options
author | Tim Peters <tim.peters@gmail.com> | 2005-02-15 16:22:34 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2005-02-15 16:22:34 (GMT) |
commit | 90718a4eb5a21d903d9cefdb7f8cdb50e847187b (patch) | |
tree | 1020789c8b03fe30b04234695cd92a5a4c19dfa7 /Lib/pickletools.py | |
parent | f0588583475fed46adac06dce59d82f7f34ca966 (diff) | |
download | cpython-90718a4eb5a21d903d9cefdb7f8cdb50e847187b.zip cpython-90718a4eb5a21d903d9cefdb7f8cdb50e847187b.tar.gz cpython-90718a4eb5a21d903d9cefdb7f8cdb50e847187b.tar.bz2 |
An instance of class PicklingError was used here simply as an example of
_some_ user-defined class instance. That it was also an exception isn't
interesting, but does interfere with Michael Hudson's new-style exception
patch. This just changes the doctest example, to use an instance of a
non-exception class.
Diffstat (limited to 'Lib/pickletools.py')
-rw-r--r-- | Lib/pickletools.py | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/Lib/pickletools.py b/Lib/pickletools.py index d1ee5e8..98f80f1 100644 --- a/Lib/pickletools.py +++ b/Lib/pickletools.py @@ -1996,6 +1996,11 @@ def dis(pickle, out=None, memo=None, indentlevel=4): if stack: raise ValueError("stack not empty after STOP: %r" % stack) +# For use in the doctest, simply as an example of a class to pickle. +class _Example: + def __init__(self, value): + self.value = value + _dis_test = r""" >>> import pickle >>> x = [1, 2, (3, 4), {'abc': u"def"}] @@ -2060,27 +2065,27 @@ Exercise the INST/OBJ/BUILD family. 18: . STOP highest protocol among opcodes = 0 ->>> x = [pickle.PicklingError()] * 2 +>>> from pickletools import _Example +>>> x = [_Example(42)] * 2 >>> dis(pickle.dumps(x, 0)) 0: ( MARK 1: l LIST (MARK at 0) 2: p PUT 0 5: ( MARK - 6: i INST 'pickle PicklingError' (MARK at 5) + 6: i INST 'pickletools _Example' (MARK at 5) 28: p PUT 1 31: ( MARK 32: d DICT (MARK at 31) 33: p PUT 2 - 36: S STRING 'args' - 44: p PUT 3 - 47: ( MARK - 48: t TUPLE (MARK at 47) - 49: s SETITEM - 50: b BUILD - 51: a APPEND - 52: g GET 1 - 55: a APPEND - 56: . STOP + 36: S STRING 'value' + 45: p PUT 3 + 48: I INT 42 + 52: s SETITEM + 53: b BUILD + 54: a APPEND + 55: g GET 1 + 58: a APPEND + 59: . STOP highest protocol among opcodes = 0 >>> dis(pickle.dumps(x, 1)) @@ -2088,20 +2093,20 @@ highest protocol among opcodes = 0 1: q BINPUT 0 3: ( MARK 4: ( MARK - 5: c GLOBAL 'pickle PicklingError' + 5: c GLOBAL 'pickletools _Example' 27: q BINPUT 1 29: o OBJ (MARK at 4) 30: q BINPUT 2 32: } EMPTY_DICT 33: q BINPUT 3 - 35: U SHORT_BINSTRING 'args' - 41: q BINPUT 4 - 43: ) EMPTY_TUPLE - 44: s SETITEM - 45: b BUILD - 46: h BINGET 2 - 48: e APPENDS (MARK at 3) - 49: . STOP + 35: U SHORT_BINSTRING 'value' + 42: q BINPUT 4 + 44: K BININT1 42 + 46: s SETITEM + 47: b BUILD + 48: h BINGET 2 + 50: e APPENDS (MARK at 3) + 51: . STOP highest protocol among opcodes = 1 Try "the canonical" recursive-object test. |