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

Rework some "private" functions in semver.version? #309

Closed

Description

@tomschr

Situation

Currently, we have the following module level functions inside semver.version:

  • comparator: a decorator that wraps a version binary operator method to allow type checks. This is only used in the Version/VersionInfo class.

  • ensure_str: a function to make sure we have always (Unicode) strings regardless if we pass a str or bytes type. Used in semver.version.Version.parse method.

  • cmd: a function that is used inside _nat_cmp and Version.compare.

Proposed Solution

IMHO the above function shouldn't be part of our public API as they are hardly used outside of semver. Their use cases are very limited. Additionally, we should discourage using these functions in user's code as they mainly act as helper functions for semver's Version class.

As such, I propose:

  • Rename the above function and add a _ (underscore) prefix. This marks this name "private" and therefore it is not part of the public API anymore.

  • Remove the function ensure_str. It was introduced just as a compatibility layer for Python2/3. IMHO it is better to integrate the code directly into semver.version.Version.parse.

  • If possible and feasible, move cmd and _nat_cmd into the Version class.

As we are going to publish a new major release, I think this is a good opportunity to tackle this.

@python-semver/reviewers @tlaferriere what do you think? Any objections?

Activity

  1. added
    Enhancement
    on Nov 3, 2020
  2. self-assigned this
    on Nov 3, 2020
  3. added
    Question
    on Nov 3, 2020
  4. changed the title [-]Make some function of semver.version "private"?[/-] [+]Rework some "private" functions in semver.version?[/+] on Nov 5, 2020
  5. added 2 commits that reference this issue on Nov 8, 2020
    b65619d
    42fd668
  6. tlaferriere commented on Nov 10, 2020

    @tlaferriere
    Contributor

    I've got no objections on this. This is going to make the API much cleaner.

  7. added a commit that references this issue on Nov 10, 2020
    201d783
  8. added a commit that references this issue on Nov 10, 2020
    13ad4ab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

EnhancementQuestion

Type

No type

Fields

SIze

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions