Skip to content

Commit

Permalink
Remove namedtuple inheritance (#93)
Browse files Browse the repository at this point in the history
Closes #87
Closes #94
Add entries to CHANGELOG
  • Loading branch information
scls19fr committed May 26, 2018
1 parent 007dde2 commit 2754b7e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Expand Up @@ -15,6 +15,8 @@ Version 2.8.1 (WIP)

* Issue #77 (PR #47). Convert multiple tests into pytest.mark.parametrize
* Issue #89 (PR #90). Add doctests.
* Issue #40 (PR #88). Add a static parse method to VersionInfo
* Issue #87 #94 (PR #93). Remove named tuple inheritance. Fix bad rendering in Pandas DataFrame

Version 2.8.0
=============
Expand Down
33 changes: 28 additions & 5 deletions semver.py
Expand Up @@ -73,8 +73,7 @@ def parse(version):
return version_parts


class VersionInfo(collections.namedtuple(
'VersionInfo', 'major minor patch prerelease build')):
class VersionInfo:
"""
:param int major: version when you make incompatible API changes.
:param int minor: version when you add functionality in
Expand All @@ -83,7 +82,26 @@ class VersionInfo(collections.namedtuple(
:param str prerelease: an optional prerelease string
:param str build: an optional build string
"""
__slots__ = ()

def __init__(self, major, minor, patch, prerelease, build):
self.major = major
self.minor = minor
self.patch = patch
self.prerelease = prerelease
self.build = build

def _astuple(self):
return (self.major, self.minor, self.patch,
self.prerelease, self.build)

def _asdict(self):
return collections.OrderedDict((
("major", self.major),
("minor", self.minor),
("patch", self.patch),
("prerelease", self.prerelease),
("build", self.build)
))

def __eq__(self, other):
if not isinstance(other, (VersionInfo, dict)):
Expand Down Expand Up @@ -115,11 +133,16 @@ def __ge__(self, other):
return NotImplemented
return _compare_by_keys(self._asdict(), _to_dict(other)) >= 0

def __repr__(self):
s = ", ".join("%s=%r" % (key, val)
for key, val in self._asdict().items())
return "VersionInfo(%s)" % s

def __str__(self):
return format_version(*self)
return format_version(*(self._astuple()))

def __hash__(self):
return hash(tuple(self))
return hash(self._astuple())

@staticmethod
def parse(version):
Expand Down

0 comments on commit 2754b7e

Please sign in to comment.