rberga06.utils.types.Version#

class rberga06.utils.types.Version(version: str)#

Bases: Version, SupportsPydanticV2[Version | packaging.version.Version | str]

A pydantic v2-compatible packaging.version.Version subclass.

Example:

>>> class Model(pydantic.BaseModel):
...     # with packaging.version.Version, this would fail
...     v: Version
...
>>> Model(v=Version("v1.0.0"))
Model(v=<Version('1.0.0')>)
>>> Model(v=packaging.version.Version("v1.0.0"))
Model(v=<Version('1.0.0')>)
>>> Model(v="v1.0.0")
Model(v=<Version('1.0.0')>)
>>> Model.model_validate(dict(v="v1.0.0"))
Model(v=<Version('1.0.0')>)
>>> # In addition, Version behaves exactly like packaging.version.Version:
>>> Version("1.0.0") > Version("1.0.0.a2")
True

See packaging.version.Version for more details.

__init__(version: str) None#

Initialize a Version object.

Parameters:

version – The string representation of a version which will be parsed and normalized before use.

Raises:

InvalidVersion – If the version does not conform to PEP 440 in any way then this exception will be raised.

Methods

__init__(version)

Initialize a Version object.

validate(obj, /)

Instantiate this class from obj.

Attributes

base_version

The "base version" of the version.

dev

The development number of the version.

epoch

The epoch of the version.

is_devrelease

Whether this version is a development release.

is_postrelease

Whether this version is a post-release.

is_prerelease

Whether this version is a pre-release.

local

The local version segment of the version.

major

The first item of release or 0 if unavailable.

micro

The third item of release or 0 if unavailable.

minor

The second item of release or 0 if unavailable.

post

The post-release number of the version.

pre

The pre-release segment of the version.

public

The public portion of the version.

release

The components of the "release" segment of the version.

property base_version: str#

The “base version” of the version.

>>> Version("1.2.3").base_version
'1.2.3'
>>> Version("1.2.3+abc").base_version
'1.2.3'
>>> Version("1!1.2.3+abc.dev1").base_version
'1!1.2.3'

The “base version” is the public version of the project without any pre or post release markers.

property dev: int | None#

The development number of the version.

>>> print(Version("1.2.3").dev)
None
>>> Version("1.2.3.dev1").dev
1
property epoch: int#

The epoch of the version.

>>> Version("2.0.0").epoch
0
>>> Version("1!2.0.0").epoch
1
property is_devrelease: bool#

Whether this version is a development release.

>>> Version("1.2.3").is_devrelease
False
>>> Version("1.2.3.dev1").is_devrelease
True
property is_postrelease: bool#

Whether this version is a post-release.

>>> Version("1.2.3").is_postrelease
False
>>> Version("1.2.3.post1").is_postrelease
True
property is_prerelease: bool#

Whether this version is a pre-release.

>>> Version("1.2.3").is_prerelease
False
>>> Version("1.2.3a1").is_prerelease
True
>>> Version("1.2.3b1").is_prerelease
True
>>> Version("1.2.3rc1").is_prerelease
True
>>> Version("1.2.3dev1").is_prerelease
True
property local: str | None#

The local version segment of the version.

>>> print(Version("1.2.3").local)
None
>>> Version("1.2.3+abc").local
'abc'
property major: int#

The first item of release or 0 if unavailable.

>>> Version("1.2.3").major
1
property micro: int#

The third item of release or 0 if unavailable.

>>> Version("1.2.3").micro
3
>>> Version("1").micro
0
property minor: int#

The second item of release or 0 if unavailable.

>>> Version("1.2.3").minor
2
>>> Version("1").minor
0
property post: int | None#

The post-release number of the version.

>>> print(Version("1.2.3").post)
None
>>> Version("1.2.3.post1").post
1
property pre: Tuple[str, int] | None#

The pre-release segment of the version.

>>> print(Version("1.2.3").pre)
None
>>> Version("1.2.3a1").pre
('a', 1)
>>> Version("1.2.3b1").pre
('b', 1)
>>> Version("1.2.3rc1").pre
('rc', 1)
property public: str#

The public portion of the version.

>>> Version("1.2.3").public
'1.2.3'
>>> Version("1.2.3+abc").public
'1.2.3'
>>> Version("1.2.3+abc.dev1").public
'1.2.3'
property release: Tuple[int, ...]#

The components of the “release” segment of the version.

>>> Version("1.2.3").release
(1, 2, 3)
>>> Version("2.0.0").release
(2, 0, 0)
>>> Version("1!2.0.0.post0").release
(2, 0, 0)

Includes trailing zeroes but not the epoch or any pre-release / development / post-release suffixes.

classmethod validate(obj: Version | Version | str, /) Self#

Instantiate this class from obj.