Allow len(Version) to return number of split components. (#7918)

This commit is contained in:
Chris Green 2018-04-26 17:38:43 -05:00 committed by becker33
parent 310addea91
commit 6cc79f8142
2 changed files with 11 additions and 0 deletions

View file

@ -488,6 +488,14 @@ def check_repr_and_str(vrs):
check_repr_and_str('R2016a.2-3_4') check_repr_and_str('R2016a.2-3_4')
def test_len():
a = Version('1.2.3.4')
assert len(a) == len(a.version)
assert(len(a) == 4)
b = Version('2018.0')
assert(len(b) == 2)
def test_get_item(): def test_get_item():
a = Version('0.1_2-3') a = Version('0.1_2-3')
assert isinstance(a[1], int) assert isinstance(a[1], int)

View file

@ -253,6 +253,9 @@ def satisfies(self, other):
def __iter__(self): def __iter__(self):
return iter(self.version) return iter(self.version)
def __len__(self):
return len(self.version)
def __getitem__(self, idx): def __getitem__(self, idx):
cls = type(self) cls = type(self)