Skip to content

Deprecate module level functions#229

Merged
tomschr merged 1 commit intopython-semver:masterfrom
tomschr:feature/deprecationwarning
Apr 16, 2020
Merged

Deprecate module level functions#229
tomschr merged 1 commit intopython-semver:masterfrom
tomschr:feature/deprecationwarning

Conversation

@tomschr
Copy link
Member

@tomschr tomschr commented Mar 15, 2020

This PR fixes #225.

For example, the VersionInfo.bump_major() method calls semver.parse_version_info and semver.bump_major instead of having its own implementation. This has several drawbacks:

  • the VersionInfo class depends on other, "remote" function outside the class.
  • the class is not "self-contained".
  • it makes deprecating module level functions (and removing them) harder because of these dependencies.

As such, I had to move some implementation into the VersionInfo class. With this approach, we can deprecate the module level function without triggering a false positive when calling a method in VersionInfo.

This PR contains the following changes:

  • Add test cases

    • Test also missing finalize_version
    • Test the warning more thouroughly with pytest.warns instead of just pytest.deprecated_call
  • In setup.cfg, add deprecation warnings filter for pytest

  • Implement DeprecationWarning with warnings module and the new decorator deprecated

  • Output a DeprecationWarning for the following functions:

    • semver.bump_{major,minor,patch,prerelease,build}
    • semver.finalize_version
    • semver.format_version
    • semver.parse
    • semver.parse_version_info
    • semver.replace
  • Move module level implementation into VersionInfo

    • Move implementations:

      • semver.format_version -> semver.VersionInfo.format_version semver.VersionInfo.__str__
      • Move _REGEX into VersionInfo class
      • Move _LAST_NUMBER into VersionInfo class
      • Move also _increment_string and implement it as a staticmethod
      • semver.parse -> semver.VersionInfo.parse
      • semver.bump_* -> semver.VersionInfo.bump_*
    • Change implementation by calling VersionInfo methods (and not the other way around):

      • semver.compare
      • semver.finalize_version
      • semver.replace
      • semver.parse_version_info
  • Introduce new public functions:

    • semver.VersionInfo.to_dict (from former _asdict)
    • semver.VersionInfo.to_tuple (from former _astuple)
    • Keep _asdict and _astuple as a (deprecated) function for compatibility reasons
  • Update CHANGELOG.rst

  • Update usage documentation:
    - Move some information to make them more useful for the reader
    - Add deprecation warning
    - Explain how to replace deprecated functions
    - Explain how to display deprecation warnings from semver

  • Improve documentation of deprecated functions

    • List deprecated module level functions
    • Make recommendation and show equivalent code
    • Mention that deprecated functions will be replaced in semver 3. That means, all deprecated function will be still available in semver 2.x.y.

@gsakkis As you were also involved, I'd like to hear your opinion too. 😉

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

Labels

Enhancement Not a bug, but increases or improves in value, quality, desirability, or attractiveness Release_2.x.y Only for the major release 2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decide to deprecate module level functions?

4 participants