diff --git a/src/poetry/core/semver/version.py b/src/poetry/core/semver/version.py index 63d67fddc..89826a0d5 100644 --- a/src/poetry/core/semver/version.py +++ b/src/poetry/core/semver/version.py @@ -86,8 +86,6 @@ def allows(self, version: Version | None) -> bool: # allow weak equality to allow `3.0.0+local.1` for `3.0.0` if not _this.is_local() and _other.is_local(): _other = _other.without_local() - elif _this.is_local() and not _other.is_local(): - _this = _this.without_local() # allow weak equality to allow `3.0.0-1` for `3.0.0` if not _this.is_postrelease() and _other.is_postrelease(): diff --git a/src/poetry/core/semver/version_range.py b/src/poetry/core/semver/version_range.py index 6e2539a2f..55aa0e46f 100644 --- a/src/poetry/core/semver/version_range.py +++ b/src/poetry/core/semver/version_range.py @@ -81,6 +81,10 @@ def allows(self, other: Version) -> bool: if not _this.is_local() and _other.is_local(): # allow weak equality to allow `3.0.0+local.1` for `<=3.0.0` _other = _other.without_local() + elif _this.is_local() and ( + not _other.is_local() or _this.local != _other.local + ): + return False if not _this.is_postrelease() and _other.is_postrelease(): # allow weak equality to allow `3.0.0-1` for `<=3.0.0` diff --git a/tests/semver/test_version.py b/tests/semver/test_version.py index 90d3c503c..ab90cf993 100644 --- a/tests/semver/test_version.py +++ b/tests/semver/test_version.py @@ -127,7 +127,8 @@ def test_allows_with_local() -> None: assert not v.allows(Version.parse("1.3.3")) assert not v.allows(Version.parse("1.2.3-dev")) assert not v.allows(Version.parse("1.2.3+build.2")) - assert v.allows(Version.parse("1.2.3-1")) + assert not v.allows(Version.parse("1.2.3-1")) + assert v.allows(Version.parse("1.2.3-1+build.1")) assert v.allows(Version.parse("1.2.3-1+build.1")) diff --git a/tests/semver/test_version_range.py b/tests/semver/test_version_range.py index 9cd414530..4e4379e5e 100644 --- a/tests/semver/test_version_range.py +++ b/tests/semver/test_version_range.py @@ -133,8 +133,9 @@ def test_allows_post_releases_with_post_and_local_max() -> None: two = Version.parse("3.0.0-1") three = Version.parse("3.0.0-1+local.1") four = Version.parse("3.0.0+local.2") + five = Version.parse("4.0.0+local.2") - assert VersionRange(max=one, include_max=True).allows(two) + assert not VersionRange(max=one, include_max=True).allows(two) assert VersionRange(max=one, include_max=True).allows(three) assert not VersionRange(max=one, include_max=True).allows(four) @@ -143,12 +144,17 @@ def test_allows_post_releases_with_post_and_local_max() -> None: assert VersionRange(max=two, include_max=True).allows(four) assert VersionRange(max=three, include_max=True).allows(one) - assert VersionRange(max=three, include_max=True).allows(two) - assert VersionRange(max=three, include_max=True).allows(four) + assert not VersionRange(max=three, include_max=True).allows(two) + assert not VersionRange(max=three, include_max=True).allows(four) - assert VersionRange(max=four, include_max=True).allows(one) - assert VersionRange(max=four, include_max=True).allows(two) - assert VersionRange(max=four, include_max=True).allows(three) + assert not VersionRange(max=four, include_max=True).allows(one) + assert not VersionRange(max=four, include_max=True).allows(two) + assert not VersionRange(max=four, include_max=True).allows(three) + + assert not VersionRange(max=five, include_max=True).allows(one) + assert not VersionRange(max=five, include_max=True).allows(two) + assert not VersionRange(max=five, include_max=True).allows(three) + assert VersionRange(max=five, include_max=True).allows(four) @pytest.mark.parametrize( @@ -161,9 +167,9 @@ def test_allows_post_releases_with_post_and_local_max() -> None: id="post", ), pytest.param( - Version.parse("3.0.0"), Version.parse("3.0.0+local.1"), - Version.parse("3.0.0+local.2"), + Version.parse("3.0.0-1+local.1"), + Version.parse("3.0.0-2+local.1"), id="local", ), ],