Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Cannot compare with list or string #244

Copy link
Copy link
Closed
@tomschr

Description

@tomschr
Issue body actions

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

BugError, flaw or fault to produce incorrect or unexpected resultsError, flaw or fault to produce incorrect or unexpected results

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.