Skip to content

Commit 772a7a6

Browse files
tlaferrieretomschr
andauthored
Deprecate max_ver and min_ver (#264)
* Deprecate functions max_ver and min_ver * Fix typos in docs * Document use of builtins max() and min() * Fix bad doc link and change section name * Improve documentation with examples of how to use the builtin max and min. Keep the old way of doing for reference. * Test that max_ver and min_ver are deprecated. * Add deprecation to CHANGELOG.rst * Rename removals to deprecations and clean up the CHANGELOG.rst Co-authored-by: Tom Schraitle <tomschr@users.noreply.github.com>
1 parent 4841d6f commit 772a7a6

File tree

4 files changed

+80
-24
lines changed

4 files changed

+80
-24
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ Additions
2929

3030
n/a
3131

32-
Removals
32+
Deprecations
3333
--------
3434

35-
n/a
35+
* :gh:`160` (:pr:`264`):
36+
* :func:`semver.max_ver`
37+
* :func:`semver.min_ver`
3638

3739

3840
Version 2.10.1
@@ -58,14 +60,6 @@ Bug Fixes
5860
to always return a ``VersionInfo`` instance.
5961

6062

61-
Additions
62-
---------
63-
64-
65-
Removals
66-
--------
67-
68-
6963
Version 2.10.0
7064
==============
7165

@@ -95,7 +89,7 @@ Additions
9589
* :pr:`228`: Added better doctest integration
9690

9791

98-
Removals
92+
Deprecations
9993
--------
10094
* :gh:`225` (:pr:`229`): Output a DeprecationWarning for the following functions:
10195

@@ -139,12 +133,6 @@ Bug Fixes
139133
* :gh:`192` (:pr:`193`): Fixed "pysemver" and "pysemver bump" when called without arguments
140134

141135

142-
Removals
143-
--------
144-
145-
not available
146-
147-
148136
Version 2.9.0
149137
=============
150138
:Released: 2019-10-30
@@ -184,7 +172,7 @@ Bug Fixes
184172
Removals
185173
--------
186174

187-
* :gh:`111` (:pr:`110`): Droped Python 3.3
175+
* :gh:`111` (:pr:`110`): Dropped Python 3.3
188176
* :gh:`148` (:pr:`149`): Removed and replaced ``python setup.py test``
189177

190178

docs/usage.rst

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ are met.
1111
Knowing the Implemented semver.org Version
1212
------------------------------------------
1313

14-
The semver.org page is the authorative specification of how semantical
15-
versioning is definied.
16-
To know which version of semver.org is implemented in the semver libary,
14+
The semver.org page is the authoritative specification of how semantic
15+
versioning is defined.
16+
To know which version of semver.org is implemented in the semver library,
1717
use the following constant::
1818

1919
>>> semver.SEMVER_SPEC_VERSION
@@ -445,7 +445,11 @@ To compare two versions depends on your type:
445445

446446
Other types cannot be compared.
447447

448-
If you need to convert some types into other, refer to :ref:`sec.convert.versions`.
448+
If you need to convert some types into others, refer to :ref:`sec.convert.versions`.
449+
450+
The use of these comparison operators also implies that you can use builtin
451+
functions that leverage this capability; builtins including, but not limited to: :func:`max`, :func:`min`
452+
(for examples, see :ref:`sec_max_min`) and :func:`sorted`.
449453

450454

451455

@@ -476,9 +480,47 @@ That gives you the following possibilities to express your condition:
476480
>>> semver.match("1.0.0", ">1.0.0")
477481
False
478482
483+
.. _sec_max_min:
484+
485+
Getting Minimum and Maximum of Multiple Versions
486+
------------------------------------------------
487+
.. versionchanged:: 2.10.2
488+
The functions :func:`semver.max_ver` and :func:`semver.min_ver` are deprecated in
489+
favor of their builtin counterparts :func:`max` and :func:`min`.
490+
491+
Since :class:`semver.VersionInfo` implements :func:`__gt__()` and :func:`__lt__()`, it can be used with builtins requiring
492+
493+
.. code-block:: python
494+
495+
>>> max([semver.VersionInfo(0, 1, 0), semver.VersionInfo(0, 2, 0), semver.VersionInfo(0, 1, 3)])
496+
VersionInfo(major=0, minor=2, patch=0, prerelease=None, build=None)
497+
>>> min([semver.VersionInfo(0, 1, 0), semver.VersionInfo(0, 2, 0), semver.VersionInfo(0, 1, 3)])
498+
VersionInfo(major=0, minor=1, patch=0, prerelease=None, build=None)
499+
500+
Incidentally, using :func:`map`, you can get the min or max version of any number of versions of the same type
501+
(convertible to :class:`semver.VersionInfo`).
502+
503+
For example, here are the maximum and minimum versions of a list of version strings:
504+
505+
.. code-block:: python
506+
507+
>>> str(max(map(semver.VersionInfo.parse, ['1.1.0', '1.2.0', '2.1.0', '0.5.10', '0.4.99'])))
508+
'2.1.0'
509+
>>> str(min(map(semver.VersionInfo.parse, ['1.1.0', '1.2.0', '2.1.0', '0.5.10', '0.4.99'])))
510+
'0.4.99'
511+
512+
And the same can be done with tuples:
513+
514+
.. code-block:: python
515+
516+
>>> max(map(lambda v: semver.VersionInfo(*v), [(1, 1, 0), (1, 2, 0), (2, 1, 0), (0, 5, 10), (0, 4, 99)])).to_tuple()
517+
(2, 1, 0, None, None)
518+
>>> min(map(lambda v: semver.VersionInfo(*v), [(1, 1, 0), (1, 2, 0), (2, 1, 0), (0, 5, 10), (0, 4, 99)])).to_tuple()
519+
(0, 4, 99, None, None)
479520
480-
Getting Minimum and Maximum of two Versions
481-
-------------------------------------------
521+
For dictionaries, it is very similar to finding the max version tuple: see :ref:`sec.convert.versions`.
522+
523+
The "old way" with :func:`semver.max_ver` or :func:`semver.min_ver` is still available, but not recommended:
482524

483525
.. code-block:: python
484526
@@ -575,6 +617,28 @@ them with code which is compatible for future versions:
575617
>>> s1 == s2
576618
True
577619
620+
* :func:`semver.max_ver`
621+
622+
Replace it with ``max(version1, version2, ...)`` or ``max([version1, version2, ...])``:
623+
624+
.. code-block:: python
625+
626+
>>> s1 = semver.max_ver("1.2.3", "1.2.4")
627+
>>> s2 = str(max(map(semver.VersionInfo.parse, ("1.2.3", "1.2.4"))))
628+
>>> s1 == s2
629+
True
630+
631+
* :func:`semver.min_ver`
632+
633+
Replace it with ``min(version1, version2, ...)`` or ``min([version1, version2, ...])``:
634+
635+
.. code-block:: python
636+
637+
>>> s1 = semver.min_ver("1.2.3", "1.2.4")
638+
>>> s2 = str(min(map(semver.VersionInfo.parse, ("1.2.3", "1.2.4"))))
639+
>>> s1 == s2
640+
True
641+
578642
* :func:`semver.parse`
579643

580644
Replace it with :func:`semver.VersionInfo.parse` and

semver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ def match(version, match_expr):
812812
return ver.match(match_expr)
813813

814814

815+
@deprecated(replace="max", version="2.10.2")
815816
def max_ver(ver1, ver2):
816817
"""
817818
Returns the greater version of two versions strings.
@@ -835,6 +836,7 @@ def max_ver(ver1, ver2):
835836
return ver2
836837

837838

839+
@deprecated(replace="min", version="2.10.2")
838840
def min_ver(ver1, ver2):
839841
"""
840842
Returns the smaller version of two versions strings.

test_semver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,8 @@ def test_should_versioninfo_isvalid():
10361036
(parse, ("1.2.3",), {}),
10371037
(parse_version_info, ("1.2.3",), {}),
10381038
(replace, ("1.2.3",), dict(major=2, patch=10)),
1039+
(max_ver, ("1.2.3", "1.2.4"), {}),
1040+
(min_ver, ("1.2.3", "1.2.4"), {}),
10391041
],
10401042
)
10411043
def test_should_raise_deprecation_warnings(func, args, kwargs):

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