← 输入框|github.com|刷新
Skip to content

Deprecate missing module-level functions (like semver.compare, semver.match, ...) #236

Closed

Description

@tomschr

Situation

We deprecated most of our module-level functions, but it seems, I forgot semver.match.

Proposal

I assume, this function should also be added to the list of deprecated function. It also should be moved to the semver.VersionInfo class.

@python-semver/reviewers Any objections?


There are some other module-level functions:

  • semver.compare
  • semver.max_ver
  • semver.min_ver

@gsakkis: What should we do with these? Deprecate them too and move them to the semver.VersionInfo class?

Activity

  1. added
    Question
    on Apr 18, 2020
  2. self-assigned this
    on Apr 18, 2020
  3. s-celles commented on Apr 18, 2020

    @s-celles
    Member

    No objection. Python is not Julia. So let's prefer methods instead over functions.

  4. added
    Release_2.x.y
    on Apr 19, 2020
  5. changed the title [-]Deprecate semver.match?[/-] [+]Deprecate missing module-level functions (like semver.compare, semver.match, ...)[/+] on Apr 19, 2020
  6. added a commit that references this issue on Apr 21, 2020
    14cd842
  7. added a commit that references this issue on Apr 23, 2020
    d69e7c4
  8. Askaholic commented on May 17, 2020

    @Askaholic

    As someone who contributes to a project that uses this library I have to say that I disagree with these deprecations. Replacing semver.compare(version1, version2) with semver.VersionInfo.parse(version1).compare(version2) is just an ugly solution. The first one is clean, easy to read and easy to understand. The second one is ugly, and unnecessarily verbose.

    I think your refactor to use VersionInfo under the hood is a great solution, but I don't see why the compare convenience function needs to become deprecated in the process. I would guess that most use cases of this library are fairly simple, as is the case for my project, and for those use cases semver.compare is objectively better.

    Let me counter @scls19fr 's comment with this:

    Python is not Java. You do not need to make everything a class.

  9. tomschr commented on May 17, 2020

    @tomschr
    MemberAuthor

    Thanks @Askaholic I appreciate your feedback. 👍

    Well, it's a bit late after almost everything has been refactored and so much effort went into that. 😉

    I know, some parts may be verbose. If you need the compare function more often, it could be done in a less verbose variant like this:

    >>> import 
    >>> parse = semver.VersionInfo.parse
    >>> parse(version1).compare(version2)

    Of course, it depends on your taste if you think this is still "ugly" or "readable".

    Python is not Java. You do not need to make everything a class.

    To be precise, he compared Python with Julia, not Java. I agree, not everything needs to be a class in Python. In this case, I still think a version class has some advantages over a string-only representation.

    The current implementation delegates everything inside the module-level functions to the VersionInfo class. In this design, the module-level functions act as a "wrapper". So with the current version 2.10.1, you use the class anyway. These wrappers do some internal conversions to be compatible with the existing API.

    [...] but I don't see why the compare convenience function needs to become deprecated in the process.

    It's Python itself in its Zen where it states: "There should be one--and preferably only one--obvious way to do it."

    For your information, if you really dislike this change, you can still stay with major release 2 as described in https://python-semver.readthedocs.io/en/latest/install.html#release-policy

    Nothing will change in regards to the module-level functions. They stay as they are.

    With major 3 I've planned to keep them for some more releases, let's say 3.1, to make the transition a bit easier. However, after some time, I plan to remove them.

    Currently, you are the first one to raise this concern. Either others are not aware of this or they think this is not that important. If more developers raise concern and would like to keep them, we could reconsider it. However, in that case, please open a new issue where we can discuss this in a new, fresh environment.

  10. Askaholic commented on May 17, 2020

    @Askaholic

    @tomschr Thanks for the response!

    I know that I can implement my own workaround to make the code more pretty. I could just copy and paste the compare function somewhere in my codebase too. For now I've decided to pin at version 2.9 since I'm trying to get rid of warnings from my codebase. My use case is very simple, used only to support certain legacy software, and I don't expect to need any new features that may come in newer versions of semver. Hopefully I can drop the dependency completely at some point.

    I don't know about the other functions but I think you should at least consider keeping compare as it represents one of the the most basic (and maybe common) use cases of this library. I'll also point out that the readme still recommends using compare:

    To compare two versions, semver provides the semver.compare function.

    As for the "python is not X" thing. I'm just trying to say that I think statements like that are pretty meaningless because you can always just plug in a different language and make the opposite argument.

  11. tomschr commented on May 18, 2020

    @tomschr
    MemberAuthor

    @Askaholic

    For now I've decided to pin at version 2.9 since I'm trying to get rid of warnings from my codebase.

    Shouldn't be necessary, you can suppress only the semver warnings too. Use a warning filter as described in the warnings module of the Python documentation.

    I don't know about the other functions but I think you should at least consider keeping compare as it represents one of the the most basic (and maybe common) use cases of this library.

    Could you open a new issue for that, please? Thanks!

    I'll also point out that the readme still recommends using compare:

    Ahh, thanks! 👍 That was the missing part from the refactoring.

    As for the "python is not X" thing. I'm just trying to say that I think statements like that are pretty meaningless because you can always just plug in a different language and make the opposite argument.

    I'm not sure if I completely understood your sentence. We are talking about Python only.

    Of course it's not a strict law, but a rule of thumb to help deciding things. Lots of projects and developers align themselves to these rules. It's not really surprising, it belongs to Python's core philosophy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

QuestionRelease_2.x.y

Type

No type

Fields

SIze

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions