summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2012-05-18 01:17:41 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2012-05-18 01:17:41 +0200
commit76bb3e02b85dff2535b4318e46fe70f6e1564d95 (patch)
tree377d02cefd7fcc178a04bf9c4007f0c4db8113e9
parentb900fadf5ed39c80874e7ffc369b385fa5950209 (diff)
downloadsemantic-version-76bb3e02b85dff2535b4318e46fe70f6e1564d95.tar.gz
Add docstrings.
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
-rw-r--r--src/semantic_version/base.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/semantic_version/base.py b/src/semantic_version/base.py
index 05755e6..d776143 100644
--- a/src/semantic_version/base.py
+++ b/src/semantic_version/base.py
@@ -148,8 +148,25 @@ class Version(object):
def __hash__(self):
return hash((self.major, self.minor, self.patch, self.prerelease, self.build))
- def _comparison_functions(self, partial=False):
+ @classmethod
+ def _comparison_functions(cls, partial=False):
+ """Retrieve comparison methods to apply on version components.
+
+ This is a private API.
+
+ Args:
+ partial (bool): whether to provide 'partial' or 'strict' matching.
+
+ Returns:
+ 5-tuple of cmp-like functions.
+ """
+
def prerelease_cmp(a, b):
+ """Compare prerelease components.
+
+ Special rule: a version without prerelease component has higher
+ precedence than one with a prerelease component.
+ """
if a and b:
return identifier_list_cmp(a, b)
elif a:
@@ -161,6 +178,11 @@ class Version(object):
return 0
def build_cmp(a, b):
+ """Compare build components.
+
+ Special rule: a version without build component has lower
+ precedence than one with a build component.
+ """
if a and b:
return identifier_list_cmp(a, b)
elif a:
@@ -172,6 +194,7 @@ class Version(object):
return 0
def make_optional(orig_cmp_fun):
+ """Convert a cmp-like function to consider 'None == *'."""
@functools.wraps(orig_cmp_fun)
def alt_cmp_fun(a, b):
if a is None or b is None:
@@ -182,7 +205,7 @@ class Version(object):
if partial:
return [
- cmp,
+ cmp, # Major is still mandatory
make_optional(cmp),
make_optional(cmp),
make_optional(prerelease_cmp),