Use case: Introduce VersionInfo.coerce
See original GitHub issueSituation
Currently, if you parse a version string into a valid semver version, the version string has to consist of at least the major, minor, and patch parts.
However, in some use cases some parts could be missing, for example the patch part.
Proposed Solution
I propose a classmethod VersionInfo.coerce
with the following signature:
@classmethod
def coerce(cls, version):
"""
Convert an incomplete version string into a semver-compatible VersionInfo
object
* Tries to detect a "basic" version string (``major.minor.patch``).
* If not enough components can be found, missing components are
set to zero to obtain a valid semver version.
:param str version: the version string to convert
:return: a tuple with a :class:`VersionInfo` instance (or ``None``
if it's not a version) and the rest of the string which doesn't
belong to a basic version.
:rtype: tuple(:class:`VersionInfo` | None, str)
"""
I’ve chosen coerce
as it is a common function name in other semver implementations, for example, node-semver.
An example session:
>>> import semver
>>> semver.VersionInfo.coerce("v1.2")
(VersionInfo(major=1, minor=2, patch=0, prerelease=None, build=None), '')
>>> semver.VersionInfo.coerce("3.5rc1")
(VersionInfo(major=3, minor=5, patch=0, prerelease=None, build=None), 'rc1')
Questions:
- Do you you think such a function could be useful?
- Should the
coerce
function accept an integer value (=major)? Socoerce(2)
would be the same ascoerce("2")
which would returnVersionInfo(major=2, minor=0, patch=0, prerelease=None, build=None)
. - Anything else you miss, would change, …?
See also
This issue is related to #137
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
XML Query Use Cases - W3C
1.9 Use Case "STRONG" - queries that exploit strongly typed data ... The use cases listed below were created by the XML Query...
Read more >Version Control: A Good Practice Guide - University of Glasgow
Version control is the process by which different drafts and versions of a document or record are managed. It is a tool which...
Read more >Coercion Theory: A Basic Introduction for Practitioners
While coercion theory may be well understood in the academy, it is less well understood by practitioners, especially in the military.
Read more >An Introduction to Convert2RHEL: Now officially supported to ...
Flexibility- Convert2RHEL can now access RHEL content via multiple methods depending on your use case.
Read more >Extract/Introduce variable | IntelliJ IDEA Documentation
You can use the Introduce Variable refactoring to extract variadic arguments into a new slice variable. In the editor, select an expression or ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think that’s enough for now. Thanks @tomschr for your contribution.
@scls19fr Ok, let’s document this. 👍
I’ve opened PR #215 and introduced a new section “Dealing with Invalid Versions”. There I’ve used a modified
coerce()
function as an example.It’s a start, I’m not sure if this is enough. What do you think?