@@ -108,6 +108,10 @@ def normalize_pre(letter: str, /) -> str:
108108 'b'
109109 >>> normalize_pre('rc')
110110 'rc'
111+
112+ :param letter:
113+
114+ .. versionadded:: 26.1
111115 """
112116 letter = letter .lower ()
113117 return _LETTER_NORMALIZATION .get (letter , letter )
@@ -116,6 +120,8 @@ def normalize_pre(letter: str, /) -> str:
116120def parse (version : str ) -> Version :
117121 """Parse the given version string.
118122
123+ This is identical to the :class:`Version` constructor.
124+
119125 >>> parse('1.0.dev1')
120126 <Version('1.0.dev1')>
121127
@@ -249,6 +255,11 @@ def __ne__(self, other: object) -> bool:
249255regular expression should be compiled with the ``re.VERBOSE`` and ``re.IGNORECASE``
250256flags set.
251257
258+ .. versionchanged:: 26.0
259+
260+ The regex now uses possessive qualifiers on Python 3.11 if they are
261+ supported (CPython 3.11.5+, PyPy 3.11.13+).
262+
252263:meta hide-value:
253264"""
254265
@@ -353,10 +364,20 @@ class Version(_BaseVersion):
353364 False
354365 >>> v1 <= v2
355366 True
367+
368+ :class:`Version` is immutable; use :meth:`__replace__` to change
369+ part of a version.
356370 """
357371
358372 __slots__ = ("_dev" , "_epoch" , "_key_cache" , "_local" , "_post" , "_pre" , "_release" )
359373 __match_args__ = ("_str" ,)
374+ """
375+ Pattern matching is supported on Python 3.10+.
376+
377+ .. versionadded:: 26.0
378+
379+ :meta hide-value:
380+ """
360381
361382 _regex = re .compile (r"\s*" + VERSION_PATTERN + r"\s*" , re .VERBOSE | re .IGNORECASE )
362383
@@ -422,6 +443,23 @@ def from_parts(
422443 dev : int | None = None ,
423444 local : str | None = None ,
424445 ) -> Self :
446+ """
447+ Return a new version composed of the various parts.
448+
449+ This allows you to build a version without going though a string and
450+ running a regular expression. It normalizes pre-release strings. The
451+ ``release=`` keyword argument is required.
452+
453+ >>> Version.from_parts(release=(1,2,3))
454+ <Version('1.2.3')>
455+ >>> Version.from_parts(release=(0,1,0), pre=("b", 1))
456+ <Version('0.1.0b1')>
457+
458+ :param epoch:
459+ :param release: This version tuple is required
460+
461+ .. versionadded:: 26.0
462+ """
425463 _epoch = _validate_epoch (epoch )
426464 _release = _validate_release (release )
427465 _pre = _validate_pre (pre ) if pre is not None else None
@@ -441,6 +479,30 @@ def from_parts(
441479 return new_version
442480
443481 def __replace__ (self , ** kwargs : Unpack [_VersionReplace ]) -> Self :
482+ """
483+ __replace__(*, epoch=..., release=..., pre=..., post=..., dev=..., local=...)
484+
485+ Return a new version with parts replaced.
486+
487+ This returns a new version (unless no parts were changed). The
488+ pre-release is normalized. Setting a value to ``None`` clears it.
489+
490+ >>> v = Version("1.2.3")
491+ >>> v.__replace__(pre=("a", 1))
492+ <Version('1.2.3a1')>
493+
494+ :param int | None epoch:
495+ :param tuple[int, ...] | None release:
496+ :param tuple[str, int] | None pre:
497+ :param int | None post:
498+ :param int | None dev:
499+ :param str | None local:
500+
501+ .. versionadded:: 26.0
502+ .. versionchanged:: 26.1
503+
504+ The pre-release portion is now normalized.
505+ """
444506 epoch = _validate_epoch (kwargs ["epoch" ]) if "epoch" in kwargs else self ._epoch
445507 release = (
446508 _validate_release (kwargs ["release" ])
@@ -630,6 +692,9 @@ def local(self) -> str | None:
630692 def public (self ) -> str :
631693 """The public portion of the version.
632694
695+ This returns a string. If you want a :class:`Version` again and care
696+ about performance, use ``v.__replace__(local=None)`` instead.
697+
633698 >>> Version("1.2.3").public
634699 '1.2.3'
635700 >>> Version("1.2.3+abc").public
@@ -643,6 +708,10 @@ def public(self) -> str:
643708 def base_version (self ) -> str :
644709 """The "base version" of the version.
645710
711+ This returns a string. If you want a :class:`Version` again and care
712+ about performance, use
713+ ``v.__replace__(pre=None, post=None, dev=None, local=None)`` instead.
714+
646715 >>> Version("1.2.3").base_version
647716 '1.2.3'
648717 >>> Version("1.2.3+abc").base_version
@@ -790,7 +859,8 @@ def _parse_letter_version(
790859
791860def _parse_local_version (local : str | None ) -> LocalType | None :
792861 """
793- Takes a string like abc.1.twelve and turns it into ("abc", 1, "twelve").
862+ Takes a string like ``"abc.1.twelve"`` and turns it into
863+ ``("abc", 1, "twelve")``.
794864 """
795865 if local is not None :
796866 return tuple (
0 commit comments