semver 3.2.0__tar.gz → 3.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. {semver-3.2.0 → semver-3.2.1}/CHANGELOG.rst +41 -10
  2. {semver-3.2.0 → semver-3.2.1}/PKG-INFO +1 -1
  3. {semver-3.2.0 → semver-3.2.1}/docs/contribute/run-test-suite.rst +17 -21
  4. {semver-3.2.0 → semver-3.2.1}/docs/usage/check-compatible-semver-version.rst +10 -7
  5. {semver-3.2.0 → semver-3.2.1}/docs/usage/create-a-version.rst +3 -3
  6. {semver-3.2.0 → semver-3.2.1}/src/semver/__about__.py +1 -1
  7. {semver-3.2.0 → semver-3.2.1}/src/semver/version.py +70 -25
  8. {semver-3.2.0 → semver-3.2.1}/src/semver.egg-info/PKG-INFO +1 -1
  9. {semver-3.2.0 → semver-3.2.1}/src/semver.egg-info/SOURCES.txt +2 -0
  10. semver-3.2.1/tests/test_negative_fractional_parts.py +96 -0
  11. {semver-3.2.0 → semver-3.2.1}/tests/test_semver.py +20 -0
  12. semver-3.2.1/tests/test_subclass_typing.py +19 -0
  13. {semver-3.2.0 → semver-3.2.1}/tox.ini +1 -2
  14. {semver-3.2.0 → semver-3.2.1}/uv.lock +6 -6
  15. {semver-3.2.0 → semver-3.2.1}/.coveragerc +0 -0
  16. {semver-3.2.0 → semver-3.2.1}/.editorconfig +0 -0
  17. {semver-3.2.0 → semver-3.2.1}/.gitignore +0 -0
  18. {semver-3.2.0 → semver-3.2.1}/.pytest.ini +0 -0
  19. {semver-3.2.0 → semver-3.2.1}/.readthedocs.yaml +0 -0
  20. {semver-3.2.0 → semver-3.2.1}/.ruff.toml +0 -0
  21. {semver-3.2.0 → semver-3.2.1}/CITATION.cff +0 -0
  22. {semver-3.2.0 → semver-3.2.1}/CONTRIBUTING.rst +0 -0
  23. {semver-3.2.0 → semver-3.2.1}/CONTRIBUTORS +0 -0
  24. {semver-3.2.0 → semver-3.2.1}/LICENSE.txt +0 -0
  25. {semver-3.2.0 → semver-3.2.1}/MANIFEST.in +0 -0
  26. {semver-3.2.0 → semver-3.2.1}/Makefile +0 -0
  27. {semver-3.2.0 → semver-3.2.1}/README.rst +0 -0
  28. {semver-3.2.0 → semver-3.2.1}/SUPPORT.md +0 -0
  29. {semver-3.2.0 → semver-3.2.1}/changelog.d/.gitignore +0 -0
  30. {semver-3.2.0 → semver-3.2.1}/changelog.d/README.rst +0 -0
  31. {semver-3.2.0 → semver-3.2.1}/changelog.d/_template.rst +0 -0
  32. {semver-3.2.0 → semver-3.2.1}/docs/_static/css/custom.css +0 -0
  33. {semver-3.2.0 → semver-3.2.1}/docs/_static/logo.svg +0 -0
  34. {semver-3.2.0 → semver-3.2.1}/docs/_templates/layout.html +0 -0
  35. {semver-3.2.0 → semver-3.2.1}/docs/advanced/coerce.py +0 -0
  36. {semver-3.2.0 → semver-3.2.1}/docs/advanced/combine-pydantic-and-semver.rst +0 -0
  37. {semver-3.2.0 → semver-3.2.1}/docs/advanced/convert-pypi-to-semver.rst +0 -0
  38. {semver-3.2.0 → semver-3.2.1}/docs/advanced/create-subclasses-from-version.rst +0 -0
  39. {semver-3.2.0 → semver-3.2.1}/docs/advanced/deal-with-invalid-versions.rst +0 -0
  40. {semver-3.2.0 → semver-3.2.1}/docs/advanced/display-deprecation-warnings.rst +0 -0
  41. {semver-3.2.0 → semver-3.2.1}/docs/advanced/index.rst +0 -0
  42. {semver-3.2.0 → semver-3.2.1}/docs/advanced/semverwithvprefix.py +0 -0
  43. {semver-3.2.0 → semver-3.2.1}/docs/advanced/version-from-file.rst +0 -0
  44. {semver-3.2.0 → semver-3.2.1}/docs/contribute/add-changelog-entry.rst +0 -0
  45. {semver-3.2.0 → semver-3.2.1}/docs/contribute/doc-semver.rst +0 -0
  46. {semver-3.2.0 → semver-3.2.1}/docs/contribute/finish-release.rst +0 -0
  47. {semver-3.2.0 → semver-3.2.1}/docs/contribute/index.rst +0 -0
  48. {semver-3.2.0 → semver-3.2.1}/docs/contribute/prerequisites.rst +0 -0
  49. {semver-3.2.0 → semver-3.2.1}/docs/contribute/release-procedure.rst +0 -0
  50. {semver-3.2.0 → semver-3.2.1}/docs/contribute/report-bugs.rst +0 -0
  51. {semver-3.2.0 → semver-3.2.1}/docs/inventories/pydantic.inv +0 -0
  52. {semver-3.2.0 → semver-3.2.1}/docs/inventories/python-objects.inv +0 -0
  53. {semver-3.2.0 → semver-3.2.1}/docs/migration/index.rst +0 -0
  54. {semver-3.2.0 → semver-3.2.1}/docs/migration/migratetosemver3.rst +0 -0
  55. {semver-3.2.0 → semver-3.2.1}/docs/migration/replace-deprecated-functions.rst +0 -0
  56. {semver-3.2.0 → semver-3.2.1}/docs/usage/access-parts-of-a-version.rst +0 -0
  57. {semver-3.2.0 → semver-3.2.1}/docs/usage/access-parts-through-index.rst +0 -0
  58. {semver-3.2.0 → semver-3.2.1}/docs/usage/check-valid-semver-version.rst +0 -0
  59. {semver-3.2.0 → semver-3.2.1}/docs/usage/compare-versions-through-expression.rst +0 -0
  60. {semver-3.2.0 → semver-3.2.1}/docs/usage/compare-versions.rst +0 -0
  61. {semver-3.2.0 → semver-3.2.1}/docs/usage/convert-version-into-different-types.rst +0 -0
  62. {semver-3.2.0 → semver-3.2.1}/docs/usage/determine-version-equality.rst +0 -0
  63. {semver-3.2.0 → semver-3.2.1}/docs/usage/get-min-and-max-of-multiple-versions.rst +0 -0
  64. {semver-3.2.0 → semver-3.2.1}/docs/usage/increase-parts-of-a-version_prereleases.rst +0 -0
  65. {semver-3.2.0 → semver-3.2.1}/docs/usage/index.rst +0 -0
  66. {semver-3.2.0 → semver-3.2.1}/docs/usage/parse-version-string.rst +0 -0
  67. {semver-3.2.0 → semver-3.2.1}/docs/usage/raise-parts-of-a-version.rst +0 -0
  68. {semver-3.2.0 → semver-3.2.1}/docs/usage/replace-parts-of-a-version.rst +0 -0
  69. {semver-3.2.0 → semver-3.2.1}/docs/usage/semver-version.rst +0 -0
  70. {semver-3.2.0 → semver-3.2.1}/docs/usage/semver_org-version.rst +0 -0
  71. {semver-3.2.0 → semver-3.2.1}/pyproject.toml +0 -0
  72. {semver-3.2.0 → semver-3.2.1}/release-procedure.md +0 -0
  73. {semver-3.2.0 → semver-3.2.1}/setup.cfg +0 -0
  74. {semver-3.2.0 → semver-3.2.1}/src/semver/__init__.py +0 -0
  75. {semver-3.2.0 → semver-3.2.1}/src/semver/__main__.py +0 -0
  76. {semver-3.2.0 → semver-3.2.1}/src/semver/_deprecated.py +0 -0
  77. {semver-3.2.0 → semver-3.2.1}/src/semver/_types.py +0 -0
  78. {semver-3.2.0 → semver-3.2.1}/src/semver/cli.py +0 -0
  79. {semver-3.2.0 → semver-3.2.1}/src/semver/py.typed +0 -0
  80. {semver-3.2.0 → semver-3.2.1}/src/semver.egg-info/dependency_links.txt +0 -0
  81. {semver-3.2.0 → semver-3.2.1}/src/semver.egg-info/entry_points.txt +0 -0
  82. {semver-3.2.0 → semver-3.2.1}/src/semver.egg-info/requires.txt +0 -0
  83. {semver-3.2.0 → semver-3.2.1}/src/semver.egg-info/top_level.txt +0 -0
  84. {semver-3.2.0 → semver-3.2.1}/tests/coerce.py +0 -0
  85. {semver-3.2.0 → semver-3.2.1}/tests/conftest.py +0 -0
  86. {semver-3.2.0 → semver-3.2.1}/tests/semverwithvprefix.py +0 -0
  87. {semver-3.2.0 → semver-3.2.1}/tests/test_bump.py +0 -0
  88. {semver-3.2.0 → semver-3.2.1}/tests/test_bump_build_digitless.py +0 -0
  89. {semver-3.2.0 → semver-3.2.1}/tests/test_bump_token_validation.py +0 -0
  90. {semver-3.2.0 → semver-3.2.1}/tests/test_compare.py +0 -0
  91. {semver-3.2.0 → semver-3.2.1}/tests/test_compare_invalid_operands.py +0 -0
  92. {semver-3.2.0 → semver-3.2.1}/tests/test_deprecated_functions.py +0 -0
  93. {semver-3.2.0 → semver-3.2.1}/tests/test_docstrings.py +0 -0
  94. {semver-3.2.0 → semver-3.2.1}/tests/test_format.py +0 -0
  95. {semver-3.2.0 → semver-3.2.1}/tests/test_immutable.py +0 -0
  96. {semver-3.2.0 → semver-3.2.1}/tests/test_index.py +0 -0
  97. {semver-3.2.0 → semver-3.2.1}/tests/test_issue484.py +0 -0
  98. {semver-3.2.0 → semver-3.2.1}/tests/test_match.py +0 -0
  99. {semver-3.2.0 → semver-3.2.1}/tests/test_max-min.py +0 -0
  100. {semver-3.2.0 → semver-3.2.1}/tests/test_next_version_legacy_order.py +0 -0
  101. {semver-3.2.0 → semver-3.2.1}/tests/test_optional_native_backend.py +0 -0
  102. {semver-3.2.0 → semver-3.2.1}/tests/test_parsing.py +0 -0
  103. {semver-3.2.0 → semver-3.2.1}/tests/test_prefixed_example.py +0 -0
  104. {semver-3.2.0 → semver-3.2.1}/tests/test_pysemver-cli.py +0 -0
  105. {semver-3.2.0 → semver-3.2.1}/tests/test_replace.py +0 -0
  106. {semver-3.2.0 → semver-3.2.1}/tests/test_strict_parsing.py +0 -0
  107. {semver-3.2.0 → semver-3.2.1}/tests/test_subclass.py +0 -0
  108. {semver-3.2.0 → semver-3.2.1}/tests/test_typeerror-274.py +0 -0
@@ -18,6 +18,37 @@ This section covers the changes between major version 2 and version 3.
18
18
 
19
19
  .. towncrier release notes start
20
20
 
21
+
22
+ Version 3.2.1
23
+ =============
24
+
25
+ :Released: 2026-12-06
26
+ :Maintainer: Tom Schraitle
27
+
28
+
29
+ Bug Fixes
30
+ ---------
31
+
32
+ * :pr:`490`: The ``tox -e docs`` command now uses the available system ``make`` executable
33
+ instead of resolving the unrelated PyPI ``make`` package through ``uvx``.
34
+
35
+ * :pr:`527`: :meth:`~semver.version.Version.is_compatible()` now uses the same prerelease precedence rules as version comparison.
36
+
37
+ * :pr:`537`: Type checkers now preserve the concrete subclass of ``Version`` after
38
+ ``bump_*``, ``next_version()``, ``replace()``, and ``finalize_version()``.
39
+
40
+ * :gh:`531`: Negative fractional numeric version parts now raise :py:exc:`ValueError` instead of
41
+ being silently truncated to zero.
42
+
43
+
44
+ Improved Documentation
45
+ ----------------------
46
+
47
+ * :pr:`525`: Updated the contributor test guide to use supported Python environments and
48
+ current linting commands.
49
+
50
+ ----
51
+
21
52
  Version 3.2.0
22
53
  =============
23
54
 
@@ -54,7 +85,7 @@ Security
54
85
  Bug Fixes
55
86
  ---------
56
87
 
57
- * :gh:`515`: Fix :meth:`Version.__hash__` so that versions which compare equal now produce
88
+ * :gh:`515`: Fix :meth:`~semver.version.Version.__hash__` so that versions which compare equal now produce
58
89
  equal hashes. A numeric prerelease identifier with leading zeros (for example
59
90
  ``"007"``) compares equal to its normalized form (``"7"``), but previously
60
91
  hashed differently, which broke ``set`` and ``dict`` behavior.
@@ -93,7 +124,7 @@ Deprecations
93
124
  Trivial Changes
94
125
  ---------------
95
126
 
96
- * :gh:`511`: :meth:`Version.compare` now returns early when both prerelease parts are equal,
127
+ * :gh:`511`: :meth:`~semver.version.Version.compare` now returns early when both prerelease parts are equal,
97
128
  or when only one version has a prerelease. This makes comparisons and sorting faster.
98
129
 
99
130
  ----
@@ -108,24 +139,24 @@ Version 3.1.1
108
139
  Bug Fixes
109
140
  ---------
110
141
 
111
- * :pr:`483`: Fix :meth:`~semver.Version.bump_prerelease` and :meth:`~semver.Version.bump_build` to raise a :class:`ValueError` when the ``token`` argument is not a valid dot-separated SemVer identifier (for example ``build+meta`` or ``rc.``). Previously such tokens were concatenated unchecked, producing version strings that :meth:`~semver.Version.parse` itself would reject.
142
+ * :pr:`483`: Fix :meth:`~semver.version.Version.bump_prerelease` and :meth:`~semver.version.Version.bump_build` to raise a :class:`ValueError` when the ``token`` argument is not a valid dot-separated SemVer identifier (for example ``build+meta`` or ``rc.``). Previously such tokens were concatenated unchecked, producing version strings that :meth:`~semver.Version.parse` itself would reject.
112
143
 
113
- * :pr:`486`: Fix :meth:`~semver.Version.next_version` to drop the build metadata when incrementing an old-style prerelease without a dot separator (for example ``rc3``). Previously ``1.2.3-rc3+build.5`` became ``1.2.3-rc4+build.5`` while ``1.2.3-rc.3+build.5`` became ``1.2.3-rc.4``.
144
+ * :pr:`486`: Fix :meth:`~semver.version.Version.next_version` to drop the build metadata when incrementing an old-style prerelease without a dot separator (for example ``rc3``). Previously ``1.2.3-rc3+build.5`` became ``1.2.3-rc4+build.5`` while ``1.2.3-rc.3+build.5`` became ``1.2.3-rc.4``.
114
145
 
115
- * :pr:`489`: ``Version.next_version`` now validates used prerelease tokens and matches token
146
+ * :pr:`489`: :meth:`~semver.version.Version.next_version` now validates used prerelease tokens and matches token
116
147
  families literally. Invalid tokens raise ``ValueError``. Dotted prefixes advance
117
148
  correctly while existing qualifier chains and legacy counters are preserved.
118
149
 
119
- * :pr:`495`: The type annotation of ``Version.is_valid()`` now includes its existing support for UTF-8 encoded byte strings.
150
+ * :pr:`495`: The type annotation of :meth:`~semver.version.Version.is_valid` now includes its existing support for UTF-8 encoded byte strings.
120
151
 
121
- * :pr:`501`: ``Version.replace()`` now preserves the original constructor ``TypeError``
152
+ * :pr:`501`: :meth:`~semver.version.Version.replace` now preserves the original constructor ``TypeError``
122
153
  when an existing version component receives an invalid value, rather than
123
154
  reporting zero unexpected keyword arguments.
124
155
 
125
156
  * :pr:`508`: ``Version`` subscripts now accept objects implementing ``__index__`` and raise
126
157
  ``TypeError`` for invalid key types.
127
158
 
128
- * :gh:`484`: Fix :meth:`~semver.Version.next_version` to correctly increment old-style prerelease versions without a dot separator (for example ``rc3``). Previously, calling ``next_version("prerelease")`` on such versions would reset the prerelease number to 1 instead of incrementing it.
159
+ * :gh:`484`: Fix :meth:`~semver.version.Version.next_version` to correctly increment old-style prerelease versions without a dot separator (for example ``rc3``). Previously, calling ``next_version("prerelease")`` on such versions would reset the prerelease number to 1 instead of incrementing it.
129
160
 
130
161
  * :gh:`487`: Comparing versions with long numeric prerelease identifiers no longer raises
131
162
  ``ValueError`` because of Python's integer string conversion limit.
@@ -146,7 +177,7 @@ Bug Fixes
146
177
  Trivial Changes
147
178
  ---------------
148
179
 
149
- * :pr:`502`: Add tests for six behaviours that mutation testing showed were not covered: :func:`match()` at the boundary version, build metadata in :func:`is_compatible()`, numeric-only prereleases in :func:`bump_prerelease()`, the :command:`pysemver` return code for an invalid version, and the :func:`deprecated()` messages.
180
+ * :pr:`502`: Add tests for six behaviours that mutation testing showed were not covered: :meth:`~semver.version.Version.match` at the boundary version, build metadata in :meth:`~semver.version.Version.is_compatible`, numeric-only prereleases in :meth:`~semver.version.Version.bump_prerelease`, the :command:`pysemver` return code for an invalid version, and the :func:`~semver._deprecated.deprecated()` messages.
150
181
 
151
182
 
152
183
  ----
@@ -161,7 +192,7 @@ Version 3.1.0
161
192
  Bug Fixes
162
193
  ---------
163
194
 
164
- * :pr:`478`: ``Version.parse()`` and ``Version.is_valid()`` now reject non-ASCII digits and
195
+ * :pr:`478`: :meth:`~semver.version.Version.parse` and :meth:`~semver.version.Version.is_valid` now reject non-ASCII digits and
165
196
  trailing newlines, in accordance with the SemVer grammar. Optional minor and
166
197
  patch parsing applies the same character restrictions.
167
198
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: semver
3
- Version: 3.2.0
3
+ Version: 3.2.1
4
4
  Summary: Python helper for Semantic Versioning (https://semver.org)
5
5
  Author-email: Kostiantyn Rybnikov <k-bx@k-bx.com>, Tom Schraitle <toms@suse.de>
6
6
  Maintainer-email: Tom Schraitle <toms@suse.de>, Sebastien Celles <s.celles@gmail.com>
@@ -16,18 +16,15 @@ You can decide to run the complete test suite or only part of it:
16
16
 
17
17
  $ tox
18
18
 
19
- If you have not all Python interpreters installed on your system
20
- it will probably give you some errors (``InterpreterNotFound``).
21
- To avoid such errors, use::
22
-
23
- $ tox --skip-missing-interpreters
19
+ The configured ``skip_missing_interpreters`` option skips Python
20
+ interpreters that are not installed on your system.
24
21
 
25
22
  It is possible to use one or more specific Python versions. Use the ``-e``
26
- option and one or more abbreviations (``py37`` for Python 3.7,
27
- ``py38`` for Python 3.8 etc.)::
23
+ option and one or more abbreviations (``py311`` for Python 3.11,
24
+ ``py312`` for Python 3.12 etc.)::
28
25
 
29
- $ tox -e py37
30
- $ tox -e py37,py38
26
+ $ tox -e py311
27
+ $ tox -e py311,py312
31
28
 
32
29
  To get a complete list and a short description, run::
33
30
 
@@ -37,10 +34,9 @@ You can decide to run the complete test suite or only part of it:
37
34
  ``TEST_FILE::TEST_FUNCTION``.
38
35
 
39
36
  For example, the following line tests only the function
40
- :func:`test_immutable_major` in the file :file:`test_bump.py` for all
41
- Python versions::
37
+ ``test_should_bump_major`` in the file :file:`test_bump.py` using Python 3.11::
42
38
 
43
- $ tox -e py37 -- tests/test_bump.py::test_should_bump_major
39
+ $ tox -e py311 -- tests/test_bump.py::test_should_bump_major
44
40
 
45
41
  By default, pytest prints only a dot for each test function. To
46
42
  reveal the executed test function, use the following syntax::
@@ -48,21 +44,21 @@ You can decide to run the complete test suite or only part of it:
48
44
  $ tox -- -v
49
45
 
50
46
  You can combine the specific test function with the ``-e`` option, for
51
- example, to limit the tests for Python 3.7 and 3.8 only::
47
+ example, to limit the tests for Python 3.11 and 3.12 only::
48
+
49
+ $ tox -e py311,py312 -- tests/test_bump.py::test_should_bump_major
52
50
 
53
- $ tox -e py37,py38 -- tests/test_bump.py::test_should_bump_major
51
+ The ``checks`` environment runs `Ruff`_ for code-style checks. The
52
+ ``mypy`` and ``docstrings`` environments run `mypy`_ and `docformatter`_,
53
+ respectively.
54
54
 
55
- Our code is checked against formatting, style, type, and docstring issues
56
- (`black`_, `flake8`_, `mypy`_, and `docformatter`_).
57
- It is recommended to run your tests in combination with :command:`checks`,
58
- for example::
55
+ It is recommended to run code-style checks together with the tests, for example::
59
56
 
60
- $ tox -e checks,py37,py38
57
+ $ tox -e checks,py311,py312
61
58
 
62
59
 
63
- .. _black: https://black.rtfd.io
60
+ .. _Ruff: https://docs.astral.sh/ruff/
64
61
  .. _docformatter: https://pypi.org/project/docformatter/
65
- .. _flake8: https://flake8.rtfd.io
66
62
  .. _mypy: http://mypy-lang.org/
67
63
  .. _pytest: http://pytest.org/
68
64
  .. _tox: https://tox.rtfd.org/
@@ -12,15 +12,14 @@ version ``b`` is *compatible* according to semver rule, use the method
12
12
  The expression ``a.is_compatible(b) is True`` if one of the following
13
13
  statements is true:
14
14
 
15
- * both versions are equal, or
16
- * both majors are equal and higher than 0. The same applies for both
17
- minor parts. Both pre-releases are equal, or
18
- * both majors are equal and higher than 0. The minor of ``b``'s
19
- minor version is higher then ``a``'s. Both pre-releases are equal.
15
+ * Both versions have the same precedence, including for major zero.
16
+ * Both versions have the same nonzero major, the minor version of ``b``
17
+ is at least that of ``a``, and their prereleases have equal precedence
18
+ or are both absent.
20
19
 
21
20
  In all other cases, the result is false.
22
21
 
23
- Keep in mind, the method *does not* check patches!
22
+ Build metadata is ignored. Patch versions matter only for major zero.
24
23
 
25
24
 
26
25
  * Two different majors:
@@ -78,7 +77,7 @@ Keep in mind, the method *does not* check patches!
78
77
  >>> b.is_compatible(a)
79
78
  False
80
79
 
81
- * Identical pre-releases:
80
+ * Prereleases with equal precedence:
82
81
 
83
82
  .. code-block:: python
84
83
 
@@ -86,6 +85,10 @@ Keep in mind, the method *does not* check patches!
86
85
  >>> b = Version(1, 0, 0,'rc1')
87
86
  >>> a.is_compatible(b)
88
87
  True
88
+ >>> Version(1, 2, 3, prerelease="rc.07").is_compatible(
89
+ ... Version(1, 3, 0, prerelease="rc.7")
90
+ ... )
91
+ True
89
92
 
90
93
  * All major zero versions are incompatible with anything but itself:
91
94
 
@@ -44,14 +44,14 @@ A :class:`~semver.version.Version` instance can be created in different ways:
44
44
  >>> Version(**d)
45
45
  Version(major=3, minor=4, patch=5, prerelease='pre.2', build='build.4')
46
46
 
47
- Keep in mind, the ``major``, ``minor``, ``patch`` parts has to
48
- be positive integers or strings, otherwise a :py:exc:`python:ValueError` is raised:
47
+ Use non-negative integers or their string representations for ``major``,
48
+ ``minor``, and ``patch``. A negative value raises :py:exc:`python:ValueError`:
49
49
 
50
50
  >>> d = {'major': -3, 'minor': 4, 'patch': 5, 'prerelease': 'pre.2', 'build': 'build.4'}
51
51
  >>> Version(**d)
52
52
  Traceback (most recent call last):
53
53
  ...
54
- ValueError: 'major' is negative. A version can only be positive.
54
+ ValueError: 'major' is negative. Version numbers must be non-negative.
55
55
 
56
56
  As a minimum requirement, your dictionary needs at least the ``major``
57
57
  key, others can be omitted. You get a :py:exc:`python:TypeError` if your
@@ -16,7 +16,7 @@ of the semver specifictation, author, maintainers, and description.
16
16
  """
17
17
 
18
18
  #: Semver version
19
- __version__ = "3.2.0"
19
+ __version__ = "3.2.1"
20
20
 
21
21
  #: Original semver author
22
22
  __author__ = "Kostiantyn Rybnikov"
@@ -104,14 +104,24 @@ class Version:
104
104
  :param build: an optional build string
105
105
  :raises ValueError: if a numeric part is negative or the version exceeds
106
106
  :attr:`MAX_LENGTH`
107
+
108
+ .. versionchanged:: 3.2.1
109
+
110
+ Negative fractional numeric version parts now raise
111
+ :exc:`ValueError` instead of being silently truncated to zero.
107
112
  """
108
113
 
109
114
  __slots__ = ("_major", "_minor", "_patch", "_prerelease", "_build")
110
115
 
111
116
  #: The names of the different parts of a version
112
117
  NAMES: ClassVar[Tuple[str, ...]] = tuple([item[1:] for item in __slots__])
118
+ """The names of the different parts of a version."""
113
119
 
114
- MAX_LENGTH: Final[int] = 255
120
+ MAX_LENGTH: Final[int] = 255
121
+ """Maximum length of characters of a version input string.
122
+
123
+ .. versionadded:: 3.1.3
124
+ """
115
125
 
116
126
  #: Regex for number in a build
117
127
  _LAST_NUMBER: ClassVar[Pattern[str]] = re.compile(r"(\d+)")
@@ -184,14 +194,24 @@ class Version:
184
194
  raise ValueError(length_error)
185
195
 
186
196
  # Build a dictionary of the arguments except prerelease and build
187
- version_parts = {"major": int(major), "minor": int(minor), "patch": int(patch)}
197
+ original_parts = {"major": major, "minor": minor, "patch": patch}
198
+ version_parts = {name: int(value) for name, value in original_parts.items()}
188
199
 
189
200
  # Custom __int__ methods can return huge integers, so check the converted
190
201
  # values too before rendering them for the combined-length calculation.
191
202
  for name, value in version_parts.items():
192
- if value < 0:
203
+ original = original_parts[name]
204
+ is_negative = value < 0
205
+ # For built-in integers and integer strings, int() preserves the sign.
206
+ # Other inputs can lose it, e.g. int(-0.5) is zero.
207
+ if not is_negative and type(original) not in (int, str, bytes):
208
+ try:
209
+ is_negative = original < 0 # type: ignore[operator]
210
+ except TypeError:
211
+ is_negative = False # SupportsInt does not require ordering.
212
+ if is_negative:
193
213
  raise ValueError(
194
- f"{name!r} is negative. A version can only be positive."
214
+ f"{name!r} is negative. Version numbers must be non-negative."
195
215
  )
196
216
  if value >= numeric_limit:
197
217
  raise ValueError(length_error)
@@ -386,7 +406,7 @@ class Version:
386
406
  string = string[: max(end - len(next_), start)] + next_ + string[end:]
387
407
  return string
388
408
 
389
- def bump_major(self) -> "Version":
409
+ def bump_major(self: T) -> T:
390
410
  """
391
411
  Raise the major part of the version, return a new object but leave self
392
412
  untouched.
@@ -400,7 +420,7 @@ class Version:
400
420
  cls = type(self)
401
421
  return cls(self._major + 1)
402
422
 
403
- def bump_minor(self) -> "Version":
423
+ def bump_minor(self: T) -> T:
404
424
  """
405
425
  Raise the minor part of the version, return a new object but leave self
406
426
  untouched.
@@ -414,7 +434,7 @@ class Version:
414
434
  cls = type(self)
415
435
  return cls(self._major, self._minor + 1)
416
436
 
417
- def bump_patch(self) -> "Version":
437
+ def bump_patch(self: T) -> T:
418
438
  """
419
439
  Raise the patch part of the version, return a new object but leave self
420
440
  untouched.
@@ -429,10 +449,10 @@ class Version:
429
449
  return cls(self._major, self._minor, self._patch + 1)
430
450
 
431
451
  def bump_prerelease(
432
- self,
452
+ self: T,
433
453
  token: Optional[str] = "rc",
434
454
  bump_when_empty: Optional[bool] = False
435
- ) -> "Version":
455
+ ) -> T:
436
456
  """
437
457
  Raise the prerelease part of the version, return a new object but leave
438
458
  self untouched.
@@ -479,7 +499,7 @@ class Version:
479
499
 
480
500
  return cls(self._major, self._minor, patch, prerelease)
481
501
 
482
- def bump_build(self, token: Optional[str] = "build") -> "Version":
502
+ def bump_build(self: T, token: Optional[str] = "build") -> T:
483
503
  """
484
504
  Raise the build part of the version, return a new object but leave self
485
505
  untouched.
@@ -559,12 +579,19 @@ build='build.10')
559
579
 
560
580
  return self._nat_cmp(rc1, rc2)
561
581
 
562
- def next_version(self, part: str, prerelease_token: str = "rc") -> "Version":
582
+ def next_version(self: T, part: str, prerelease_token: str = "rc") -> T:
563
583
  """
564
584
  Determines next version, preserving natural order.
565
585
 
566
586
  .. versionadded:: 2.10.0
567
587
 
588
+ .. versionchanged:: 3.1.1
589
+
590
+ Drop the build metadata when incrementing an old-style prerelease
591
+ without a dot separator (for example rc3). Previously ``1.2.3-rc3+build.5``
592
+ became ``1.2.3-rc4+build.5`` while ``1.2.3-rc.3+build.5``
593
+ became ``1.2.3-rc.4``.
594
+
568
595
  This function is taking prereleases into account.
569
596
  The "major", "minor", and "patch" raises the respective parts like
570
597
  the ``bump_*`` functions. The real difference is using the
@@ -721,6 +748,18 @@ build='build.10')
721
748
  return version
722
749
 
723
750
  def __hash__(self) -> int:
751
+ """
752
+ Compute a hash value for the version.
753
+
754
+ Versions that compare equal will have the same hash value.
755
+
756
+ :return: the hash value of the version
757
+
758
+ .. versionchanged:: 3.1.3
759
+
760
+ Equal numeric prerelease identifiers (e.g. "007" and "7")
761
+ now hash equally, fixing set and dict behavior.
762
+ """
724
763
  # Normalize the prerelease with the same key used for comparison so
725
764
  # that versions comparing equal (e.g. "007" and "7") hash equal.
726
765
  prerelease = (
@@ -730,7 +769,7 @@ build='build.10')
730
769
  )
731
770
  return hash((self.major, self.minor, self.patch, prerelease))
732
771
 
733
- def finalize_version(self) -> "Version":
772
+ def finalize_version(self: T) -> T:
734
773
  """
735
774
  Remove any prerelease and build metadata from the version.
736
775
 
@@ -806,6 +845,10 @@ build='build.10')
806
845
  .. versionchanged:: 3.0.0
807
846
  Added optional parameter ``optional_minor_and_patch`` to allow
808
847
  optional minor and patch parts.
848
+ .. versionchanged:: 3.1.0
849
+ Rejected non-ASCII digits and trailing newlines in version strings.
850
+ .. versionchanged:: 3.1.3
851
+ Rejected version strings longer than :attr:`MAX_LENGTH`.
809
852
 
810
853
  :param version: version string, at most :attr:`MAX_LENGTH` characters
811
854
  :param optional_minor_and_patch: if set to true, the version string to parse \
@@ -853,7 +896,7 @@ prerelease='pre.2', build='build.4')
853
896
 
854
897
  return cls(**matched_version_parts)
855
898
 
856
- def replace(self, **parts: Union[int, Optional[str]]) -> "Version":
899
+ def replace(self: T, **parts: Union[int, Optional[str]]) -> T:
857
900
  """
858
901
  Replace one or more parts of a version and return a new :class:`Version`
859
902
  object, but leave self untouched.
@@ -905,17 +948,17 @@ prerelease='pre.2', build='build.4')
905
948
  """
906
949
  Check if current version is compatible with other version.
907
950
 
908
- The result is True, if either of the following is true:
951
+ Major-zero versions must have the same precedence. For a nonzero
952
+ major version, the major parts must match and the other minor part
953
+ must be at least as high. Prereleases are compared by precedence.
954
+ Build metadata is ignored, and patch versions matter only for major
955
+ zero.
909
956
 
910
- * both versions are equal, or
911
- * both majors are equal and higher than 0. Same for both minors.
912
- Both pre-releases are equal, or
913
- * both majors are equal and higher than 0. The minor of b's
914
- minor version is higher then a's. Both pre-releases are equal.
957
+ .. versionadded:: 3.0.0
915
958
 
916
- The algorithm does *not* check patches.
959
+ .. versionchanged:: 3.2.1
917
960
 
918
- .. versionadded:: 3.0.0
961
+ Uses the same prerelease precedence rules as version comparison.
919
962
 
920
963
  :param other: the version to check for compatibility
921
964
  :return: True, if ``other`` is compatible with the old version,
@@ -929,14 +972,16 @@ prerelease='pre.2', build='build.4')
929
972
  if not isinstance(other, Version):
930
973
  raise TypeError(f"Expected a Version type but got {type(other)}")
931
974
 
975
+ if self.major != other.major or self.minor > other.minor:
976
+ return False
977
+
932
978
  # All major-0 versions should be incompatible with anything but itself
933
- if (0 == self.major == other.major) and (self[:4] != other[:4]):
979
+ if self.major == 0 and (self.minor != other.minor or self.patch != other.patch):
934
980
  return False
935
981
 
936
982
  return (
937
- (self.major == other.major)
938
- and (other.minor >= self.minor)
939
- and (self.prerelease == other.prerelease)
983
+ self.prerelease == other.prerelease
984
+ or self._nat_cmp(self.prerelease, other.prerelease) == 0
940
985
  )
941
986
 
942
987
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: semver
3
- Version: 3.2.0
3
+ Version: 3.2.1
4
4
  Summary: Python helper for Semantic Versioning (https://semver.org)
5
5
  Author-email: Kostiantyn Rybnikov <k-bx@k-bx.com>, Tom Schraitle <toms@suse.de>
6
6
  Maintainer-email: Tom Schraitle <toms@suse.de>, Sebastien Celles <s.celles@gmail.com>
@@ -93,6 +93,7 @@ tests/test_index.py
93
93
  tests/test_issue484.py
94
94
  tests/test_match.py
95
95
  tests/test_max-min.py
96
+ tests/test_negative_fractional_parts.py
96
97
  tests/test_next_version_legacy_order.py
97
98
  tests/test_optional_native_backend.py
98
99
  tests/test_parsing.py
@@ -102,4 +103,5 @@ tests/test_replace.py
102
103
  tests/test_semver.py
103
104
  tests/test_strict_parsing.py
104
105
  tests/test_subclass.py
106
+ tests/test_subclass_typing.py
105
107
  tests/test_typeerror-274.py
@@ -0,0 +1,96 @@
1
+ """Regression coverage for negative numbers truncated to zero by int()."""
2
+
3
+ from decimal import Decimal
4
+ from fractions import Fraction
5
+ from numbers import Number
6
+
7
+ import pytest
8
+
9
+ from semver import Version
10
+
11
+
12
+ class IntegerLike(Number):
13
+ def __init__(self, value):
14
+ self.value = value
15
+
16
+ def __int__(self):
17
+ return int(self.value)
18
+
19
+
20
+ class OrderedNumber(IntegerLike):
21
+ def __lt__(self, other):
22
+ return self.value < other
23
+
24
+
25
+ @pytest.mark.parametrize("part", ["major", "minor", "patch"])
26
+ @pytest.mark.parametrize(
27
+ "value", [-0.5, Decimal("-0.5"), Fraction(-1, 2), OrderedNumber(-0.5)]
28
+ )
29
+ def test_reject_negative_fractional_parts(part, value):
30
+ with pytest.raises(ValueError, match=f"'{part}' is negative"):
31
+ Version(**{"major": 1, part: value})
32
+
33
+
34
+ @pytest.mark.parametrize("part", ["major", "minor", "patch"])
35
+ @pytest.mark.parametrize(
36
+ "value",
37
+ [
38
+ 0,
39
+ False,
40
+ True,
41
+ -0.0,
42
+ Decimal("-0"),
43
+ 0.5,
44
+ 1.9,
45
+ Decimal("0.5"),
46
+ Fraction(1, 2),
47
+ "0",
48
+ b"0",
49
+ IntegerLike(0),
50
+ IntegerLike(2),
51
+ OrderedNumber(0.5),
52
+ ],
53
+ )
54
+ def test_preserve_nonnegative_integer_conversion(part, value):
55
+ version = Version(**{"major": 1, part: value})
56
+ assert getattr(version, part) == int(value)
57
+
58
+
59
+ @pytest.mark.parametrize("value", [-1, "-1", IntegerLike(-1)])
60
+ def test_reject_converted_negative_integers(value):
61
+ with pytest.raises(ValueError, match="'major' is negative"):
62
+ Version(value)
63
+
64
+
65
+ def test_check_original_sign_even_if_custom_int_returns_positive():
66
+ class Magnitude(int):
67
+ def __int__(self):
68
+ return abs(self)
69
+
70
+ with pytest.raises(ValueError, match="'major' is negative"):
71
+ Version(Magnitude(-1))
72
+
73
+
74
+ @pytest.mark.parametrize("part", ["major", "minor", "patch"])
75
+ def test_replace_rejects_negative_fractional_parts(part):
76
+ original = Version(1, 2, 3)
77
+ with pytest.raises(ValueError, match=f"'{part}' is negative"):
78
+ original.replace(**{part: -0.5})
79
+ assert original.to_tuple() == (1, 2, 3, None, None)
80
+
81
+
82
+ @pytest.mark.parametrize(
83
+ ("value", "error"),
84
+ [
85
+ (float("inf"), OverflowError),
86
+ (float("-inf"), OverflowError),
87
+ (Decimal("Infinity"), OverflowError),
88
+ (Decimal("-Infinity"), OverflowError),
89
+ (float("nan"), ValueError),
90
+ (Decimal("NaN"), ValueError),
91
+ (Decimal("sNaN"), ValueError),
92
+ ],
93
+ )
94
+ def test_preserve_nonfinite_conversion_errors(value, error):
95
+ with pytest.raises(error):
96
+ Version(value)
@@ -218,3 +218,23 @@ def test_should_succeed_with_compatible_subclass_for_is_compatible():
218
218
  )
219
219
  def test_should_ignore_build_metadata_in_is_compatible(old, new):
220
220
  assert Version(*old).is_compatible(Version(*new))
221
+
222
+
223
+ @pytest.mark.parametrize(
224
+ "old,new",
225
+ [
226
+ (Version(0, 1, 2), Version(0, 1, 2, prerelease="")),
227
+ (Version(1, 2, 3, prerelease=""), Version(1, 2, 3)),
228
+ (Version(0, 1, 2, prerelease="rc.07"), Version(0, 1, 2, prerelease="rc.7")),
229
+ ],
230
+ )
231
+ def test_equal_versions_are_compatible_with_equivalent_prereleases(old, new):
232
+ assert old == new
233
+ assert old.is_compatible(new)
234
+ assert new.is_compatible(old)
235
+
236
+
237
+ def test_is_compatible_uses_prerelease_precedence_for_minor_updates():
238
+ old = Version(1, 2, 3, prerelease="rc.07")
239
+ assert old.is_compatible(Version(1, 3, 0, prerelease="rc.7"))
240
+ assert not old.is_compatible(Version(1, 3, 0, prerelease="rc.8"))
@@ -0,0 +1,19 @@
1
+ from semver import Version
2
+
3
+
4
+ def test_version_updates_preserve_subclass() -> None:
5
+ class TaggedVersion(Version):
6
+ pass
7
+
8
+ version = TaggedVersion.parse("1.2.3-rc.1+build.2")
9
+ updates: tuple[TaggedVersion, ...] = (
10
+ version.bump_major(),
11
+ version.bump_minor(),
12
+ version.bump_patch(),
13
+ version.bump_prerelease(),
14
+ version.bump_build(),
15
+ version.next_version("prerelease"),
16
+ version.finalize_version(),
17
+ version.replace(minor=4),
18
+ )
19
+ assert all(type(updated) is TaggedVersion for updated in updates)
@@ -61,9 +61,8 @@ skip_install = true
61
61
  allowlist_externals =
62
62
  make
63
63
  echo
64
- uvx
65
64
  commands =
66
- uvx make -C docs html
65
+ make -C docs html
67
66
  commands_post =
68
67
  echo "Find the HTML documentation at file://{toxinidir}/docs/_build/html/index.html"
69
68
 
@@ -490,16 +490,16 @@ wheels = [
490
490
 
491
491
  [[package]]
492
492
  name = "filelock"
493
- version = "4.3.1"
493
+ version = "4.3.3"
494
494
  source = { registry = "https://pypi.org/simple" }
495
495
  resolution-markers = [
496
496
  "python_full_version >= '3.15'",
497
497
  "python_full_version >= '3.12' and python_full_version < '3.15'",
498
498
  "python_full_version == '3.11.*'",
499
499
  ]
500
- sdist = { url = "https://files.pythonhosted.org/packages/e6/86/a5b9ec254b90efb180e390e31a4fa50a93b714d6e4174fa9a4ee25607159/filelock-4.3.1.tar.gz", hash = "sha256:4c5ee627c401f1863ac6a0de9a14a28d3bb5f8c730b45e2fd6e5dbc79cf34b9e", size = 742330, upload-time = "2026-11-23T18:01:13.656Z" }
500
+ sdist = { url = "https://files.pythonhosted.org/packages/40/b8/a74f3f881abc18a1c5a79db682eeaef2913703dc9c1b7abb39b880285f5b/filelock-4.3.3.tar.gz", hash = "sha256:91d2427a74e2a5e78a1c94fc348dc8803b5f3f64dc5d6e6bab10bad29278650f", size = 746439, upload-time = "2026-12-04T18:20:48.789Z" }
501
501
  wheels = [
502
- { url = "https://files.pythonhosted.org/packages/53/7b/678c8fbd372ff96375ac0bbdd20b78f20ef8ba6ca5966c49548fa5886557/filelock-4.3.1-py3-none-any.whl", hash = "sha256:79e43df8e9fe509cd83a3899a7c186c8077cbbe4d200a1ed3705c2f3bb6bc487", size = 244559, upload-time = "2026-11-23T18:01:12.261Z" },
502
+ { url = "https://files.pythonhosted.org/packages/89/27/26e0ff3ad56081f0b33527ca308ff7ca75bbb6783013f63ba4f1f6cfa894/filelock-4.3.3-py3-none-any.whl", hash = "sha256:a03c1dac54ffe24bd0e8478b37aa19d8f89186a9ccc90e2acac88ad809deb3b3", size = 245561, upload-time = "2026-12-04T18:20:47.249Z" },
503
503
  ]
504
504
 
505
505
  [[package]]
@@ -1053,7 +1053,7 @@ resolution-markers = [
1053
1053
  "python_full_version == '3.11.*'",
1054
1054
  ]
1055
1055
  dependencies = [
1056
- { name = "filelock", version = "4.3.1", source = { registry = "https://pypi.org/simple" } },
1056
+ { name = "filelock", version = "4.3.3", source = { registry = "https://pypi.org/simple" } },
1057
1057
  ]
1058
1058
  sdist = { url = "https://files.pythonhosted.org/packages/cb/4e/20a9c45c4bb839e6e03e5971a546c623d12f950aa496cf344dc8e9f07167/python_discovery-1.9.6.tar.gz", hash = "sha256:383aa67858d73a9585a843a37a4383c6be98e4d86a981a031328e393a6eb2632", size = 147742, upload-time = "2026-11-18T00:32:26.272Z" }
1059
1059
  wheels = [
@@ -1523,7 +1523,7 @@ resolution-markers = [
1523
1523
  dependencies = [
1524
1524
  { name = "cachetools" },
1525
1525
  { name = "colorama" },
1526
- { name = "filelock", version = "4.3.1", source = { registry = "https://pypi.org/simple" } },
1526
+ { name = "filelock", version = "4.3.3", source = { registry = "https://pypi.org/simple" } },
1527
1527
  { name = "packaging" },
1528
1528
  { name = "platformdirs" },
1529
1529
  { name = "pluggy" },
@@ -1613,7 +1613,7 @@ source = { registry = "https://pypi.org/simple" }
1613
1613
  dependencies = [
1614
1614
  { name = "distlib" },
1615
1615
  { name = "filelock", version = "4.1.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" },
1616
- { name = "filelock", version = "4.3.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" },
1616
+ { name = "filelock", version = "4.3.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" },
1617
1617
  { name = "packaging" },
1618
1618
  { name = "platformdirs" },
1619
1619
  { name = "python-discovery", version = "1.6.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes