From c24f4e2157438be40b44e6ba02d90c6bfa934454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Fri, 23 Aug 2019 19:26:24 +0200 Subject: Fix inconsistent matching behaviour. According to the stated goal of "intuitive" behaviour, we want: ``Version('0.1.1-a1') not in Spec('<0.1.1')``. Tests, code and docs have been fixed. --- semantic_version/base.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'semantic_version') diff --git a/semantic_version/base.py b/semantic_version/base.py index 8251efa..1caffa5 100644 --- a/semantic_version/base.py +++ b/semantic_version/base.py @@ -441,7 +441,7 @@ class Version: base_cmp, # Major is still mandatory make_optional(base_cmp), make_optional(base_cmp), - make_optional(prerelease_cmp), + prerelease_cmp, make_optional(build_cmp), ] else: @@ -568,6 +568,8 @@ class SpecItem: if self.kind == self.KIND_ANY: return True elif self.kind == self.KIND_LT: + if version.prerelease and self.spec.prerelease is None: + version = Version(major=version.major, minor=version.minor, patch=version.patch) return version < self.spec elif self.kind == self.KIND_LTE: return version <= self.spec @@ -578,6 +580,8 @@ class SpecItem: elif self.kind == self.KIND_GT: return version > self.spec elif self.kind == self.KIND_NEQ: + if version.prerelease and version.truncate() == self.spec.truncate() and self.spec.prerelease is None: + return False return version != self.spec elif self.kind == self.KIND_CARET: if self.spec.major != 0: -- cgit v1.2.1