cloudpipe / cloudpipe/cloudpickle
inconsistent pickle result in 1.2.2
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 195
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 1
Description
My test program is
```
import cloudpickle
print(cloudpickle.__version__)
class Hello(object):
def __init__(self):
self.a = 0
h = Hello()
p1 = cloudpickle.dumps(h)
cloudpickle.loads(p1)
p2 = cloudpickle.dumps(h)
assert p1==p2
```
And I ran it with Python 3.6.5. It fails the assertion
```
1.2.2
Traceback (most recent call last):
File "algo/code.py", line 15, in
assert p1==p2
AssertionError
```
When I look at the difference in the pickle strings with `pickletools`, the difference is in the class `Hello`. In the first run, it shows
```
317: ( MARK
318: K BININT1 1
320: K BININT1 0
322: K BININT1 1
324: K BININT1 2
326: K BININT1 67
328: C SHORT_BINBYTES b'd\x01|\x00_\x00d\x00S\x00'
340: \x94 MEMOIZE (as 31)
341: N NONE
342: K BININT1 0
344: \x86 TUPLE2
345: \x94 MEMOIZE (as 32)
346: \x8c SHORT_BINUNICODE 'a'
349: \x94 MEMOIZE (as 33)
350: \x85 TUPLE1
351: \x94 MEMOIZE (as 34)
352: \x8c SHORT_BINUNICODE 'self'
358: \x94 MEMOIZE (as 35)
359: \x85 TUPLE1
360: \x94 MEMOIZE (as 36)
361: \x8c SHORT_BINUNICODE 'algo/code.py'
375: \x94 MEMOIZE (as 37)
376: h BINGET 23
378: K BININT1 5
380: C SHORT_BINBYTES b'\x00\x01'
384: \x94 MEMOIZE (as 38)
385: ) EMPTY_TUPLE
386: ) EMPTY_TUPLE
387: t TUPLE (MARK at 317)
```
while in the second run, it shows
```
317: ( MARK
318: K BININT1 1
320: K BININT1 0
322: K BININT1 1
324: K BININT1 2
326: K BININT1 67
328: C SHORT_BINBYTES b'd\x01|\x00_\x00d\x00S\x00'
340: \x94 MEMOIZE (as 31)
341: N NONE
342: K BININT1 0
344: \x86 TUPLE2
345: \x94 MEMOIZE (as 32)
346: \x8c SHORT_BINUNICODE 'a'
349: \x94 MEMOIZE (as 33)
350: \x85 TUPLE1
351: \x94 MEMOIZE (as 34)
352: \x8c SHORT_BINUNICODE 'self'
358: \x94 MEMOIZE (as 35)
359: \x85 TUPLE1
360: \x94 MEMOIZE (as 36)
361: \x8c SHORT_BINUNICODE 'algo/code.py'
375: \x94 MEMOIZE (as 37)
376: \x8c SHORT_BINUNICODE '__init__'
386: \x94 MEMOIZE (as 38)
387: K BININT1 5
389: C SHORT_BINBYTES b'\x00\x01'
393: \x94 MEMOIZE (as 39)
394: ) EMPTY_TUPLE
395: ) EMPTY_TUPLE
396: t TUPLE (MARK at 317)
```
Note how in one instance it's `__init__` spelled out, the other is a `BINGET` (albeit the actual value is the same). Is this a bug in cloudpickle? How do I work around this issue?
Also note that the line `cloudpickle.loads(p1)` is crucial. Without that line this bug wouldn't get triggered.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.