Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1d3a1733
Commit
1d3a1733
authored
Nov 30, 2013
by
Alexandre Vassalotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #16231: Allow false values other than None to be used as persistent IDs.
parent
72a01b29
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
19 deletions
+28
-19
Lib/pickle.py
Lib/pickle.py
+1
-1
Lib/test/pickletester.py
Lib/test/pickletester.py
+22
-18
Misc/NEWS
Misc/NEWS
+5
-0
No files found.
Lib/pickle.py
View file @
1d3a1733
...
...
@@ -269,7 +269,7 @@ class Pickler:
def
save
(
self
,
obj
):
# Check for persistent id (defined by a subclass)
pid
=
self
.
persistent_id
(
obj
)
if
pid
:
if
pid
is
not
None
:
self
.
save_pers
(
pid
)
return
...
...
Lib/test/pickletester.py
View file @
1d3a1733
...
...
@@ -1152,30 +1152,34 @@ class AbstractPersistentPicklerTests(unittest.TestCase):
if
isinstance
(
object
,
int
)
and
object
%
2
==
0
:
self
.
id_count
+=
1
return
str
(
object
)
elif
object
==
"test_false_value"
:
self
.
false_count
+=
1
return
""
else
:
return
None
def
persistent_load
(
self
,
oid
):
self
.
load_count
+=
1
object
=
int
(
oid
)
assert
object
%
2
==
0
return
object
if
not
oid
:
self
.
load_false_count
+=
1
return
"test_false_value"
else
:
self
.
load_count
+=
1
object
=
int
(
oid
)
assert
object
%
2
==
0
return
object
def
test_persistence
(
self
):
self
.
id_count
=
0
self
.
load_count
=
0
L
=
range
(
10
)
self
.
assertEqual
(
self
.
loads
(
self
.
dumps
(
L
)),
L
)
self
.
assertEqual
(
self
.
id_count
,
5
)
self
.
assertEqual
(
self
.
load_count
,
5
)
def
test_bin_persistence
(
self
):
self
.
id_count
=
0
self
.
load_count
=
0
L
=
range
(
10
)
self
.
assertEqual
(
self
.
loads
(
self
.
dumps
(
L
,
1
)),
L
)
self
.
assertEqual
(
self
.
id_count
,
5
)
self
.
assertEqual
(
self
.
load_count
,
5
)
L
=
range
(
10
)
+
[
"test_false_value"
]
for
proto
in
protocols
:
self
.
id_count
=
0
self
.
false_count
=
0
self
.
load_false_count
=
0
self
.
load_count
=
0
self
.
assertEqual
(
self
.
loads
(
self
.
dumps
(
L
,
proto
)),
L
)
self
.
assertEqual
(
self
.
id_count
,
5
)
self
.
assertEqual
(
self
.
false_count
,
1
)
self
.
assertEqual
(
self
.
load_count
,
5
)
self
.
assertEqual
(
self
.
load_false_count
,
1
)
class
AbstractPicklerUnpicklerObjectTests
(
unittest
.
TestCase
):
...
...
Misc/NEWS
View file @
1d3a1733
...
...
@@ -15,6 +15,11 @@ Core and Builtins
Library
-------
- Issue #16231: Fixed pickle.Pickler to only fallback to its default pickling
behaviour when Pickler.persistent_id returns None, but not for any other
false values. This allows false values other values other than None to be
used as persistent IDs. This behaviour is consistent with cPickle.
- Issue #11508: Fixed uuid.getnode() and uuid.uuid1() on environment with
virtual interface. Original patch by Kent Frazier.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment