Closed
Description
Situation
A VersionInfo
instance has the ability to compare with another VersionInfo
instance, a tuple, or a dict :
>>> import semver
>>> v1 = semver.VersionInfo.parse("1.2.3")
>>> v1 < (1, 2, 4)
True
However, it is not possible for a list or a string:
>>> v1 < [1, 2, 4]
Traceback (most recent call last):
...
TypeError: other type <class 'list'> must be in (<class 'semver.VersionInfo'>, <class 'dict'>, <class 'tuple'>)
>>> v1 < "1.2.4"
Traceback (most recent call last):
...
TypeError: other type <class 'str'> must be in (<class 'semver.VersionInfo'>, <class 'dict'>, <class 'tuple'>)
Situation
After analyzing the situation above, I found the comparator
which allows VersionInfo
instance, a tuple, or a dict :
def comparator(operator):
"""Wrap a VersionInfo binary op method in a type-check."""
@wraps(operator)
def wrapper(self, other):
comparable_types = (VersionInfo, dict, tuple) # bug!
if not isinstance(other, comparable_types):
raise TypeError(
"other type %r must be in %r" % (type(other), comparable_types)
)
return operator(self, other)
return wrapper
We should add a list and a string to the allowed types.
Would that be ok @python-semver/reviewers?
Metadata
Metadata
Assignees
Labels
Error, flaw or fault to produce incorrect or unexpected resultsError, flaw or fault to produce incorrect or unexpected results