Commit 950415ca by Jongbin Park Committed by Sébastien Eustace

Fix PEP440 compatible release (`~=`) handling (#1815)

* Fix PEP440 compatible release (`~=`) handling

PEP440 compatible release version range (`~=`) should have itself as a minimum
value. Examples from [official
doc](https://python.org/dev/peps/pep-0440/#compatible-release) (each pair is
equivalent):

```
~=2.2
>=2.2, ==2.*

~=1.4.5
>=1.4.5, ==1.4.*

~=2.2.post3
>=2.2.post3, ==2.*

~=1.4.5a4
>=1.4.5a4, ==1.4.*
```

In every case, lower bound is exactly same as the input version. Current
incorrect behavior was originally introduced 2 years ago by commit c55d55a8,
where it tried to reset patch version to 0 for tilde expression.

Closes #1150.

* Fix Black lint
parent ce9ea77d
...@@ -76,14 +76,12 @@ def parse_single_constraint(constraint): # type: (str) -> VersionConstraint ...@@ -76,14 +76,12 @@ def parse_single_constraint(constraint): # type: (str) -> VersionConstraint
version = Version.parse(m.group(1)) version = Version.parse(m.group(1))
if precision == 2: if precision == 2:
low = version
high = version.stable.next_major high = version.stable.next_major
else: else:
low = Version(version.major, version.minor, version.patch)
high = version.stable.next_minor high = version.stable.next_minor
return VersionRange( return VersionRange(
low, high, include_min=True, always_include_max_prerelease=True version, high, include_min=True, always_include_max_prerelease=True
) )
# Caret range # Caret range
......
...@@ -68,6 +68,10 @@ def test_parse_constraint_wildcard(input, constraint): ...@@ -68,6 +68,10 @@ def test_parse_constraint_wildcard(input, constraint):
("~3.5", VersionRange(Version(3, 5, 0), Version(3, 6, 0), True)), ("~3.5", VersionRange(Version(3, 5, 0), Version(3, 6, 0), True)),
("~=3.5", VersionRange(Version(3, 5, 0), Version(4, 0, 0), True)), # PEP 440 ("~=3.5", VersionRange(Version(3, 5, 0), Version(4, 0, 0), True)), # PEP 440
("~=3.5.3", VersionRange(Version(3, 5, 3), Version(3, 6, 0), True)), # PEP 440 ("~=3.5.3", VersionRange(Version(3, 5, 3), Version(3, 6, 0), True)), # PEP 440
(
"~=3.5.3rc1",
VersionRange(Version(3, 5, 3, pre="rc1"), Version(3, 6, 0), True),
), # PEP 440
], ],
) )
def test_parse_constraint_tilde(input, constraint): def test_parse_constraint_tilde(input, constraint):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment