Skip to content

Commit 5a28b4d

Browse files
Simplify highest_proto_for_py_version().
1 parent 0604d9d commit 5a28b4d

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

Lib/test/test_xpickle.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
# Python binary to execute and its arguments.
2626
py_executable_map = {}
2727

28+
protocols_map = {
29+
3: (3, 0),
30+
4: (3, 4),
31+
5: (3, 8),
32+
}
33+
2834
def highest_proto_for_py_version(py_version):
2935
"""Finds the highest supported pickle protocol for a given Python version.
3036
Args:
@@ -33,20 +39,12 @@ def highest_proto_for_py_version(py_version):
3339
Returns:
3440
int for the highest supported pickle protocol
3541
"""
36-
major = sys.version_info.major
37-
minor = sys.version_info.minor
38-
# Versions older than py 3 only supported up until protocol 2.
39-
if py_version < (3, 0):
40-
return 2
41-
elif py_version < (3, 4):
42-
return 3
43-
elif py_version < (3, 8):
44-
return 4
45-
elif py_version <= (major, minor):
46-
return 5
47-
else:
48-
# Safe option.
49-
return 2
42+
proto = 2
43+
for p, v in protocols_map.items():
44+
if py_version < v:
45+
break
46+
proto = p
47+
return proto
5048

5149
def have_python_version(py_version):
5250
"""Check whether a Python binary exists for the given py_version and has

0 commit comments

Comments
 (0)