Skip to content

next_version("prerelease") returns a lower version when switching to an earlier prerelease token #497

Open

Description

@Debasishhh

Which version of Python is the problem with?

3.9 (not version specific)

What semver version are you using?

master (84561d5)

What OS are you using?

macOS

Situation

Since #472 (fix for #339), next_version("prerelease", prerelease_token=...) resets to <token>.1 whenever the token differs from the current one. When the new token sorts before the current one, the result is a lower version, which contradicts the docstring ("Determines next version, preserving natural order").

How to reproduce

>>> from semver import Version
>>> v = Version.parse("1.2.3-rc.1")
>>> n = v.next_version("prerelease", prerelease_token="alpha")
>>> n
Version(major=1, minor=2, patch=3, prerelease='alpha.1', build=None)
>>> n > v
False

Same for 1.2.3-beta.3 -> alpha (1.2.3-alpha.1) and 1.2.3-rc.1 -> dev (1.2.3-dev.1). dev -> rc works only because rc sorts after dev.

Expected behavior

next_version always returns a version greater than self. Two options I can see when <token>.1 would not be greater:

  1. Bump the patch and start the new token there: 1.2.3-rc.1 -> 1.2.4-alpha.1 (mirrors what next_version already does for a version without a prerelease).
  2. Raise ValueError, since going from rc to alpha within the same release is probably a mistake.

Which do you prefer? Happy to send a PR with tests and a changelog entry.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    SIze

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions