Skip to content

Commit 1b1a7f1

Browse files
committed
Forbid prefix version matching on pre-release/post-release segments
It does not make much sense to have this. Let's forbid it.
1 parent e404434 commit 1b1a7f1

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

packaging/specifiers.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,21 @@ class Specifier(BaseSpecifier):
128128
v?
129129
(?:[0-9]+!)? # epoch
130130
[0-9]+(?:\.[0-9]+)* # release
131-
(?: # pre release
132-
[-_\.]?
133-
(a|b|c|rc|alpha|beta|pre|preview)
134-
[-_\.]?
135-
[0-9]*
136-
)?
137-
(?: # post release
138-
(?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
139-
)?
140131
141-
# You cannot use a wild card and a dev or local version
142-
# together so group them with a | and make them optional.
132+
# You cannot use a wild card and a pre-release, post-release, a dev or
133+
# local version together so group them with a | and make them optional.
143134
(?:
144135
\.\* # Wild card syntax of .*
145136
|
137+
(?: # pre release
138+
[-_\.]?
139+
(a|b|c|rc|alpha|beta|pre|preview)
140+
[-_\.]?
141+
[0-9]*
142+
)?
143+
(?: # post release
144+
(?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
145+
)?
146146
(?:[-_\.]?dev[-_\.]?[0-9]*)? # dev release
147147
(?:\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*)? # local
148148
)?

tests/test_specifiers.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ def test_specifiers_valid(self, specifier):
6464
# support one or the other
6565
"==1.0.*+5",
6666
"!=1.0.*+deadbeef",
67-
# Prefix matching cannot be used inside of a local version
67+
# Prefix matching cannot be used with a pre-release, post-release,
68+
# dev or local version
69+
"==2.0a1.*",
70+
"!=2.0a1.*",
71+
"==2.0.post1.*",
72+
"!=2.0.post1.*",
73+
"==2.0.dev1.*",
74+
"!=2.0.dev1.*",
6875
"==1.0+5.*",
6976
"!=1.0+deadbeef.*",
7077
# Prefix matching must appear at the end
@@ -304,8 +311,6 @@ def test_comparison_non_specifier(self):
304311
("2", "==2.*"),
305312
("2.0", "==2.*"),
306313
("2.0.0", "==2.*"),
307-
("2.0.post1", "==2.0.post1.*"),
308-
("2.0.post1.dev1", "==2.0.post1.*"),
309314
("2.1+local.version", "==2.1.*"),
310315
# Test the in-equality operation
311316
("2.1", "!=2"),
@@ -401,8 +406,6 @@ def test_comparison_non_specifier(self):
401406
("2", "!=2.*"),
402407
("2.0", "!=2.*"),
403408
("2.0.0", "!=2.*"),
404-
("2.0.post1", "!=2.0.post1.*"),
405-
("2.0.post1.dev1", "!=2.0.post1.*"),
406409
# Test the greater than equal operation
407410
("2.0.dev1", ">=2"),
408411
("2.0a1", ">=2"),
@@ -526,7 +529,6 @@ def test_specifier_prereleases_detection(self, specifier, expected):
526529
(">=1.0", "2.0.dev1", False),
527530
(">=2.0.dev1", "2.0a1", True),
528531
("==2.0.*", "2.0a1.dev1", False),
529-
("==2.0a1.*", "2.0a1.dev1", True),
530532
("<=2.0", "1.0.dev1", False),
531533
("<=2.0.dev1", "1.0a1", True),
532534
],

0 commit comments

Comments
 (0)