Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 01121f2

Browse files
committed
Merged upstream changes.
2 parents 22fa067 + 40e0f35 commit 01121f2

3 files changed

Lines changed: 25 additions & 11 deletions

File tree

Lib/packaging/tests/test_version.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class VersionTestCase(unittest.TestCase):
1616
(V('1.2'), '1.2'),
1717
(V('1.2.3a4'), '1.2.3a4'),
1818
(V('1.2c4'), '1.2c4'),
19+
(V('4.17rc2'), '4.17rc2'),
1920
(V('1.2.3.4'), '1.2.3.4'),
2021
(V('1.2.3.4.0b3'), '1.2.3.4b3'),
2122
(V('1.2.0.0.0'), '1.2'),
@@ -146,6 +147,14 @@ def test_comparison(self):
146147
"""
147148
doctest.script_from_examples(comparison_doctest_string)
148149

150+
# the doctest above is never run, so temporarily add real unit
151+
# tests until the doctest is rewritten
152+
self.assertLessEqual(V('1.2.0rc1'), V('1.2.0'))
153+
self.assertGreater(V('1.0'), V('1.0c2'))
154+
self.assertGreater(V('1.0'), V('1.0rc2'))
155+
self.assertGreater(V('1.0rc2'), V('1.0rc1'))
156+
self.assertGreater(V('1.0c4'), V('1.0c1'))
157+
149158
def test_suggest_normalized_version(self):
150159

151160
self.assertEqual(suggest('1.0'), '1.0')

Lib/packaging/version.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@
1111
# A marker used in the second and third parts of the `parts` tuple, for
1212
# versions that don't have those segments, to sort properly. An example
1313
# of versions in sort order ('highest' last):
14-
# 1.0b1 ((1,0), ('b',1), ('f',))
15-
# 1.0.dev345 ((1,0), ('f',), ('dev', 345))
16-
# 1.0 ((1,0), ('f',), ('f',))
17-
# 1.0.post256.dev345 ((1,0), ('f',), ('f', 'post', 256, 'dev', 345))
18-
# 1.0.post345 ((1,0), ('f',), ('f', 'post', 345, 'f'))
14+
# 1.0b1 ((1,0), ('b',1), ('z',))
15+
# 1.0.dev345 ((1,0), ('z',), ('dev', 345))
16+
# 1.0 ((1,0), ('z',), ('z',))
17+
# 1.0.post256.dev345 ((1,0), ('z',), ('z', 'post', 256, 'dev', 345))
18+
# 1.0.post345 ((1,0), ('z',), ('z', 'post', 345, 'z'))
1919
# ^ ^ ^
20-
# 'b' < 'f' ---------------------/ | |
20+
# 'b' < 'z' ---------------------/ | |
2121
# | |
22-
# 'dev' < 'f' < 'post' -------------------/ |
22+
# 'dev' < 'z' ----------------------------/ |
2323
# |
24-
# 'dev' < 'f' ----------------------------------------------/
25-
# Other letters would do, but 'f' for 'final' is kind of nice.
26-
_FINAL_MARKER = ('f',)
24+
# 'dev' < 'z' ----------------------------------------------/
25+
# 'f' for 'final' would be kind of nice, but due to bugs in the support of
26+
# 'rc' we must use 'z'
27+
_FINAL_MARKER = ('z',)
2728

2829
_VERSION_RE = re.compile(r'''
2930
^
@@ -167,8 +168,9 @@ def parts_to_str(cls, parts):
167168
if prerel is not _FINAL_MARKER:
168169
s += prerel[0]
169170
s += '.'.join(str(v) for v in prerel[1:])
171+
# XXX clean up: postdev is always true; code is obscure
170172
if postdev and postdev is not _FINAL_MARKER:
171-
if postdev[0] == 'f':
173+
if postdev[0] == _FINAL_MARKER[0]:
172174
postdev = postdev[1:]
173175
i = 0
174176
while i < len(postdev):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ Core and Builtins
508508
Library
509509
-------
510510

511+
- Issue #11841: Fix comparison bug with 'rc' versions in packaging.version.
512+
Patch by Filip Gruszczyński.
513+
511514
- Issue #13447: Add a test file to host regression tests for bugs in the
512515
scripts found in the Tools directory.
513516

0 commit comments

Comments
 (0)