neuralqx.utils.module.version.version module

Strict semantic version abstraction.

class Version(value='0')

Bases: object

Strict semantic version object used by neuraLQX.

This class is the canonical, strongly-typed representation of versions inside neuralqx.utils.module.version. It wraps packaging.version.Version and enforces full PEP 440 validation at construction time.

This class does not perform lexical fallbacks, every comparison is semantic and every input must be parseable as a valid version.

Accepted constructor inputs
Version accepts version-like values via VersionInput, including:
  • Version instances

  • string versions (for example "1.2.3", "1.2.3rc1", "1.2.3.post1")

  • integer versions (for example 1 -> "1")

  • component sequences (for example (1, 2, 3) -> "1.2.3")

  • packaging.version.Version instances

Comparison semantics
Ordering follows PEP 440 exactly. For the same base release X.Y.Z:

dev < a (alpha) < b (beta) < rc < final < post.

Examples

  • Version("1.1.0.dev1") < Version("1.1.0.dev2") < Version("1.1.0")

  • Version("1.1.0") < Version("1.1.0.post1")

  • Version("1.1.0rc1") < Version("1.1.0")

Error behavior
Exposed properties
  • source: normalized textual source used to build the object.

  • canonical: canonical PEP 440 form.

  • release: release tuple from the parsed version.

  • major, minor, patch: convenience release components.

Notes
  • Use NeuralqxVersion when you explicitly need string-subclass behavior.

  • Use Version for strict policy checks, ordering, and dependency gating.

property source: str

Original normalised textual source.

property canonical: str

Canonical PEP 440 normalised string.

property release: tuple[int, ...]
property major: int
property minor: int
property patch: int
as_tuple(*, width=3, fill=0)

Return release components padded/truncated to width.

Return type:

tuple[int, ...]

classmethod try_parse(value)
Return type:

Version | None

parse_version(value)

Parse a strict semantic version.

Return type:

Version

try_parse_version(value)

Attempt to parse, returning None when parsing fails.

Return type:

Version | None

coerce_version(value)

Alias for parse_version().

Return type:

Version

normalize_version(value, *, width=3, strict=True)

Convert a version-like value into a release tuple.

If strict=False, invalid values are normalised to zeros.

Return type:

tuple[int, ...]