@@ -54,17 +54,20 @@ The preferred way to create a new version is with the class
54
54
55
55
A :class: `~semver.version.Version ` instance can be created in different ways:
56
56
57
- * From a Unicode string ::
57
+ * Without any arguments ::
58
58
59
59
>>> from semver.version import Version
60
- >>> Version.parse("3.4.5-pre.2+build.4")
60
+ >>> Version()
61
+ Version(major=0, minor=0, patch=0, prerelease=None, build=None)
62
+
63
+ * From a Unicode string::
64
+
65
+ >>> Version("3.4.5-pre.2+build.4")
61
66
Version(major=3, minor=4, patch=5, prerelease='pre.2', build='build.4')
62
- >>> Version.parse(u"5.3.1")
63
- Version(major=5, minor=3, patch=1, prerelease=None, build=None)
64
67
65
68
* From a byte string::
66
69
67
- >>> Version.parse (b"2.3.4")
70
+ >>> Version(b"2.3.4")
68
71
Version(major=2, minor=3, patch=4, prerelease=None, build=None)
69
72
70
73
* From individual parts by a dictionary::
@@ -100,6 +103,32 @@ A :class:`~semver.version.Version` instance can be created in different ways:
100
103
>>> Version("3", "5", 6)
101
104
Version(major=3, minor=5, patch=6, prerelease=None, build=None)
102
105
106
+ It is possible to combine, positional and keyword arguments. In
107
+ some use cases you have a fixed version string, but would like to
108
+ replace parts of them. For example::
109
+
110
+ >>> Version(1, 2, 3, major=2, build="b2")
111
+ Version(major=2, minor=2, patch=3, prerelease=None, build='b2')
112
+
113
+ It is also possible to use a version string and replace specific
114
+ parts::
115
+
116
+ >>> Version("1.2.3", major=2, build="b2")
117
+ Version(major=2, minor=2, patch=3, prerelease=None, build='b2')
118
+
119
+ However, it is not possible to use a string and additional positional
120
+ arguments:
121
+
122
+ >>> Version(" 1.2.3" , 4 )
123
+ Traceback (most recent call last):
124
+ ...
125
+ ValueError: You cannot pass a string and additional positional arguments
126
+
127
+
128
+
129
+ Using Deprecated Functions to Create a Version
130
+ ----------------------------------------------
131
+
103
132
The old, deprecated module level functions are still available but
104
133
using them are discoraged. They are available to convert old code
105
134
to semver3.
@@ -130,17 +159,7 @@ Depending on your use case, the following methods are available:
130
159
>>> semver.parse("1.2")
131
160
Traceback (most recent call last):
132
161
...
133
- ValueError: 1.2 is not valid SemVer string
134
-
135
-
136
- Parsing a Version String
137
- ------------------------
138
-
139
- "Parsing" in this context means to identify the different parts in a string.
140
- Use the function :func: `Version.parse <semver.version.Version.parse> `::
141
-
142
- >>> Version.parse("3.4.5-pre.2+build.4")
143
- Version(major=3, minor=4, patch=5, prerelease='pre.2', build='build.4')
162
+ ValueError: '1.2' is not valid SemVer string
144
163
145
164
146
165
Checking for a Valid Semver Version
@@ -167,7 +186,7 @@ parts of a version:
167
186
168
187
.. code-block :: python
169
188
170
- >> > v = Version.parse (" 3.4.5-pre.2+build.4" )
189
+ >> > v = Version(" 3.4.5-pre.2+build.4" )
171
190
>> > v.major
172
191
3
173
192
>> > v.minor
@@ -436,7 +455,7 @@ To compare two versions depends on your type:
436
455
>>> v > "1.0"
437
456
Traceback (most recent call last):
438
457
...
439
- ValueError: 1.0 is not valid SemVer string
458
+ ValueError: ' 1.0' is not valid SemVer string
440
459
441
460
* **A ** :class: `Version <semver.version.Version> ` **type and a ** :func: `dict `
442
461
0 commit comments