Skip to content

feature request: Version comparison with str ? #465

@neutrinoceros

Description

@neutrinoceros

Would it make sense to add support for direct comparison between Version objects and str ?
Currently when using packaging.version.Version to write 'versioned code branches' to support multiple versions of a third party package (e.g. foo), one need to import the Version class everywhere versions are being compared, which means that each module needs to import and parse the version for foo, or import it from a common module (say a.py), and import Version.

# a.py
import foo
from packaging.version import Version

FOO_VERSION = Version(foo.__version__)

# b.py
from .a import FOO_VERSION
from packaging.version import Version

if FOO_VERSION >= Version("2.0"):
    ...
else:
    ...

Now say the Version class knows how to compare with str directly, the b.py module could be simplified as

# b.py
from .a import FOO_VERSION

if FOO_VERSION >= "2.0":
    ...
else:
    ...

now multiply this by dozens of modules and more branches, and this noticeably alleviates the maintenance cost of these branches.

I would like to offer such a contribution, but is this something people other than me are interested in ?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions