@@ -43,18 +43,14 @@ def ensure_str(s: String, encoding="utf-8", errors="strict") -> str:
43
43
* `bytes` -> decoded to `str`
44
44
45
45
:param s: the string to convert
46
- :type s: str | bytes
47
46
:param encoding: the encoding to apply, defaults to "utf-8"
48
- :type encoding: str
49
47
:param errors: set a different error handling scheme,
50
48
defaults to "strict".
51
49
Other possible values are `ignore`, `replace`, and
52
50
`xmlcharrefreplace` as well as any other name
53
51
registered with :func:`codecs.register_error`.
54
- :type errors: str
55
52
:raises TypeError: if ``s`` is not str or bytes type
56
53
:return: the converted string
57
- :rtype: str
58
54
"""
59
55
if isinstance (s , bytes ):
60
56
s = s .decode (encoding , errors )
@@ -218,7 +214,7 @@ def build(self, value):
218
214
219
215
def to_tuple (self ) -> VersionTuple :
220
216
"""
221
- Convert the VersionInfo object to a tuple.
217
+ Convert the Version object to a tuple.
222
218
223
219
.. versionadded:: 2.10.0
224
220
Renamed ``VersionInfo._astuple`` to ``VersionInfo.to_tuple`` to
@@ -233,7 +229,7 @@ def to_tuple(self) -> VersionTuple:
233
229
234
230
def to_dict (self ) -> VersionDict :
235
231
"""
236
- Convert the VersionInfo object to an OrderedDict.
232
+ Convert the Version object to an OrderedDict.
237
233
238
234
.. versionadded:: 2.10.0
239
235
Renamed ``VersionInfo._asdict`` to ``VersionInfo.to_dict`` to
@@ -257,7 +253,7 @@ def to_dict(self) -> VersionDict:
257
253
)
258
254
259
255
def __iter__ (self ) -> VersionIterator :
260
- """Implement iter(self)."""
256
+ """Return iter(self)."""
261
257
yield from self .to_tuple ()
262
258
263
259
@staticmethod
@@ -300,7 +296,6 @@ def bump_minor(self) -> "Version":
300
296
301
297
:return: new object with the raised minor part
302
298
303
-
304
299
>>> ver = semver.parse("3.4.5")
305
300
>>> ver.bump_minor()
306
301
Version(major=3, minor=5, patch=0, prerelease=None, build=None)
@@ -313,8 +308,7 @@ def bump_patch(self) -> "Version":
313
308
Raise the patch part of the version, return a new object but leave self
314
309
untouched.
315
310
316
- :return: new object with the raised patch part
317
-
311
+ :return: new object with the raised patch part
318
312
319
313
>>> ver = semver.parse("3.4.5")
320
314
>>> ver.bump_patch()
@@ -328,7 +322,7 @@ def bump_prerelease(self, token: str = "rc") -> "Version":
328
322
Raise the prerelease part of the version, return a new object but leave
329
323
self untouched.
330
324
331
- :param token: defaults to 'rc'
325
+ :param token: defaults to ``rc``
332
326
:return: new object with the raised prerelease part
333
327
334
328
>>> ver = semver.parse("3.4.5")
@@ -345,7 +339,7 @@ def bump_build(self, token: str = "build") -> "Version":
345
339
Raise the build part of the version, return a new object but leave self
346
340
untouched.
347
341
348
- :param token: defaults to ' build'
342
+ :param token: defaults to `` build``
349
343
:return: new object with the raised build part
350
344
351
345
>>> ver = semver.parse("3.4.5-rc.1+build.9")
@@ -365,7 +359,6 @@ def compare(self, other: Comparable) -> int:
365
359
:return: The return value is negative if ver1 < ver2,
366
360
zero if ver1 == ver2 and strictly positive if ver1 > ver2
367
361
368
-
369
362
>>> semver.compare("2.0.0")
370
363
-1
371
364
>>> semver.compare("1.0.0")
@@ -481,14 +474,17 @@ def __getitem__(
481
474
self , index : Union [int , slice ]
482
475
) -> Union [int , Optional [str ], Tuple [Union [int , str ], ...]]:
483
476
"""
484
- self.__getitem__(index) <==> self[index] Implement getitem. If the part
485
- requested is undefined, or a part of the range requested is undefined,
486
- it will throw an index error. Negative indices are not supported.
477
+ self.__getitem__(index) <==> self[index] Implement getitem.
478
+
479
+ If the part requested is undefined, or a part of the range requested
480
+ is undefined, it will throw an index error.
481
+ Negative indices are not supported.
487
482
488
483
:param Union[int, slice] index: a positive integer indicating the
489
484
offset or a :func:`slice` object
490
485
:raises IndexError: if index is beyond the range or a part is None
491
486
:return: the requested part of the version at position index
487
+
492
488
>>> ver = semver.Version.parse("3.4.5")
493
489
>>> ver[0], ver[1], ver[2]
494
490
(3, 4, 5)
@@ -519,7 +515,6 @@ def __repr__(self) -> str:
519
515
return "%s(%s)" % (type (self ).__name__ , s )
520
516
521
517
def __str__ (self ) -> str :
522
- """str(self)"""
523
518
version = "%d.%d.%d" % (self .major , self .minor , self .patch )
524
519
if self .prerelease :
525
520
version += "-%s" % self .prerelease
@@ -533,7 +528,9 @@ def __hash__(self) -> int:
533
528
def finalize_version (self ) -> "Version" :
534
529
"""
535
530
Remove any prerelease and build metadata from the version.
531
+
536
532
:return: a new instance with the finalized version string
533
+
537
534
>>> str(semver.Version.parse('1.2.3-rc.5').finalize_version())
538
535
'1.2.3'
539
536
"""
@@ -545,12 +542,12 @@ def match(self, match_expr: str) -> bool:
545
542
Compare self to match a match expression.
546
543
547
544
:param match_expr: operator and version; valid operators are
548
- < smaller than
549
- > greater than
550
- >= greator or equal than
551
- <= smaller or equal than
552
- == equal
553
- != not equal
545
+ ``<``` smaller than
546
+ ``>`` greater than
547
+ ``>=`` greator or equal than
548
+ ``<=`` smaller or equal than
549
+ ``==`` equal
550
+ ``!=`` not equal
554
551
:return: True if the expression matches the version, otherwise False
555
552
556
553
>>> semver.Version.parse("2.0.0").match(">=1.0.0")
@@ -589,18 +586,18 @@ def match(self, match_expr: str) -> bool:
589
586
@classmethod
590
587
def parse (cls , version : String ) -> "Version" :
591
588
"""
592
- Parse version string to a VersionInfo instance.
589
+ Parse version string to a Version instance.
593
590
594
591
.. versionchanged:: 2.11.0
595
592
Changed method from static to classmethod to
596
593
allow subclasses.
597
594
598
595
:param version: version string
599
- :return: a :class:`VersionInfo ` instance
596
+ :return: a new :class:`Version ` instance
600
597
:raises ValueError: if version is invalid
601
598
602
599
>>> semver.Version.parse('3.4.5-pre.2+build.4')
603
- VersionInfo (major=3, minor=4, patch=5, \
600
+ Version (major=3, minor=4, patch=5, \
604
601
prerelease='pre.2', build='build.4')
605
602
"""
606
603
version_str = ensure_str (version )
@@ -624,15 +621,15 @@ def replace(self, **parts: Union[int, Optional[str]]) -> "Version":
624
621
``major``, ``minor``, ``patch``, ``prerelease``, or ``build``
625
622
:return: the new :class:`Version` object with the changed
626
623
parts
627
- :raises TypeError: if ``parts`` contains invalid keys
624
+ :raises TypeError: if ``parts`` contain invalid keys
628
625
"""
629
626
version = self .to_dict ()
630
627
version .update (parts )
631
628
try :
632
629
return Version (** version ) # type: ignore
633
630
except TypeError :
634
631
unknownkeys = set (parts ) - set (self .to_dict ())
635
- error = "replace() got %d unexpected keyword " " argument(s): %s" % (
632
+ error = "replace() got %d unexpected keyword argument(s): %s" % (
636
633
len (unknownkeys ),
637
634
", " .join (unknownkeys ),
638
635
)
0 commit comments