Skip to content

Commit c4ac0ec

Browse files
committed
Improve documentation of deprecated functions
* List deprecated module level functions * Make recommendation and show equivalent code * Mention that deprecated functions will be replaced in major 4 of semver. That means, they will be still available in semver 3.
1 parent 1e53a15 commit c4ac0ec

File tree

3 files changed

+118
-5
lines changed

3 files changed

+118
-5
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Removals
4040
- ``semver.replace``
4141
- ``semver.VersionInfo._asdict`` (use the new, public available
4242
function ``semver.VersionInfo.to_dict()``)
43+
- ``semver.VersionInfo._astuple`` (use the new, public available
44+
function ``semver.VersionInfo.to_tuple()``)
4345

4446
These functions will be removed in major 4 of semver.
4547

docs/usage.rst

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ are met.
1414
Knowing the Implemented semver.org Version
1515
------------------------------------------
1616

17-
The semver.org is the authorative specification of how semantical versioning is
18-
definied. To know which version of semver.org is implemented in the semver
19-
libary, use the following constant::
17+
The semver.org page is the authorative specification of how semantical
18+
versioning is definied.
19+
To know which version of semver.org is implemented in the semver libary,
20+
use the following constant::
2021

2122
>>> semver.SEMVER_SPEC_VERSION
2223
'2.0.0'
@@ -25,6 +26,25 @@ libary, use the following constant::
2526
Creating a Version
2627
------------------
2728

29+
Due to historical reasons, the semver project offers two ways of
30+
creating a version:
31+
32+
* through an object oriented approach with the :class:`semver.VersionInfo`
33+
class. This is the preferred method when using semver.
34+
35+
* through module level functions and builtin datatypes (usually strings
36+
and dicts).
37+
These method are still available for compatibility reasons, but are
38+
marked as deprecated. Using one of these will emit a DeprecationWarning.
39+
40+
41+
.. warning:: **Deprecation Warning**
42+
43+
Module level functions are marked as *deprecated* in version 2.9.2 now.
44+
These functions will be removed in semver 4.
45+
For details, see section :ref:`sec_replace_deprecated_functions`.
46+
47+
2848
A version can be created in different ways:
2949

3050
* as a complete version string::
@@ -362,8 +382,96 @@ For example:
362382

363383
.. code-block:: python
364384
365-
>>> coerce("v1.2")
385+
>>> coerce("v1.2")
366386
(VersionInfo(major=1, minor=2, patch=0, prerelease=None, build=None), '')
367387
>>> coerce("v2.5.2-bla")
368388
(VersionInfo(major=2, minor=5, patch=2, prerelease=None, build=None), '-bla')
369389
390+
391+
.. _sec_replace_deprecated_functions:
392+
393+
Replacing Deprecated Functions
394+
------------------------------
395+
396+
The development team of semver has decided to deprecate certain functions on
397+
the module level. The preferred way of using semver is through the
398+
:class:`semver.VersionInfo` class.
399+
400+
The deprecated functions can still be used until semver 3. In version 4 of
401+
semver, the deprecated functions will be removed.
402+
403+
The following list shows the deprecated functions and how you can replace
404+
them with code which is compatible for future versions:
405+
406+
407+
* :func:`semver.bump_major`, :func:`semver.bump_minor`, :func:`semver.bump_patch`, :func:`semver.bump_prerelease`, :func:`semver.bump_build`
408+
409+
Replace them with the respective methods of the :class:`semver.VersionInfo`
410+
class.
411+
For example, the function :func:`semver.bump_major` is replaced by
412+
:func:`semver.VersionInfo.bump_major` and calling the ``str(versionobject)``:
413+
414+
.. code-block:: python
415+
416+
>>> s1 = semver.bump_major("3.4.5")
417+
>>> s2 = str(semver.VersionInfo.parse("3.4.5").bump_major())
418+
>>> s1 == s2
419+
True
420+
421+
Likewise with the other module level functions.
422+
423+
* :func:`semver.finalize_version`
424+
425+
Replace it with :func:`semver.VersionInfo.finalize_version`:
426+
427+
.. code-block:: python
428+
429+
>>> s1 = semver.finalize_version('1.2.3-rc.5')
430+
>>> s2 = str(semver.VersionInfo.parse('1.2.3-rc.5').finalize_version())
431+
>>> s1 == s2
432+
True
433+
434+
* :func:`semver.format_version`
435+
436+
Replace it with ``str(versionobject)``:
437+
438+
.. code-block:: python
439+
440+
>>> s1 = semver.format_version(5, 4, 3, 'pre.2', 'build.1')
441+
>>> s2 = str(semver.VersionInfo(5, 4, 3, 'pre.2', 'build.1'))
442+
>>> s1 == s2
443+
True
444+
445+
* :func:`semver.parse`
446+
447+
Replace it with :func:`semver.VersionInfo.parse` and
448+
:func:`semver.VersionInfo.to_dict`:
449+
450+
.. code-block:: python
451+
452+
>>> v1 = semver.parse("1.2.3")
453+
>>> v2 = semver.VersionInfo.parse("1.2.3").to_dict()
454+
>>> v1 == v2
455+
True
456+
457+
* :func:`semver.parse_version_info`
458+
459+
Replace it with :func:`semver.VersionInfo.parse`:
460+
461+
.. code-block:: python
462+
463+
>>> v1 = semver.parse_version_info("3.4.5")
464+
>>> v2 = semver.VersionInfo.parse("3.4.5")
465+
>>> v1 == v2
466+
True
467+
468+
* :func:`semver.replace`
469+
470+
Replace it with :func:`semver.VersionInfo.replace`:
471+
472+
.. code-block:: python
473+
474+
>>> s1 = semver.replace("1.2.3", major=2, patch=10)
475+
>>> s2 = str(semver.VersionInfo.parse('1.2.3').replace(major=2, patch=10))
476+
>>> s1 == s2
477+
True

semver.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ def deprecated(replace=None):
3232
"""
3333
Decorates a function to output a deprecation warning.
3434
35-
This function will be removed once major version 3 of semver is
35+
:param str replace: the name of the function which the deprecated
36+
function should be replaced with
37+
38+
This function will be removed once major version 4 of semver is
3639
released.
3740
"""
3841

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy