asyncutils.version¶
asyncutils. Inspired by torch.torch_version, but with quite some differences.asyncutils uses a subset of SemVer.Classes¶
A class representing a version of |
Functions¶
|
Register normalizers for |
Return the normalizer to be used for the object or type. |
|
|
|
|
Like |
Register a custom normalizer for the object or type; return whether the normalizer was newly registered. |
|
Unregister the normalizer for the object or type and return it if any. |
Module Contents¶
- class asyncutils.version.VersionDelta[source]¶
Bases:
NamedTupleA named tuple-like class representing the difference between versions.Not actually created bycollections.namedtuple(), but implements its methods.Accepted by the + or - operators.- __neg__() Self[source]¶
Return the negative of the delta. Additions and subtractions taking the return value correspond to subtractions and additions taking the original delta respectively.
- __replace__(*, major: int = ..., minor: int = ..., patch: int = ...) Self¶
Alias for
_replace().
- __trunc__() int¶
Identical to
__floor__().
- class asyncutils.version.VersionInfo[source]¶
Bases:
strA class representing a version of
asyncutils.Initialize self. See help(type(self)) for accurate signature.
- __add__(n: int, /) Self[source]¶
- __add__(delta: VersionDelta, /) Self
Return this version incremented by
npatches or the deltadelta.
- __format__(
- format_spec: Literal['x', 'hex', 'o', 'oct', 'b', 'bin', 'd', 'dec', '0', 'major', 'maj', '1', 'minor', 'min', '2', 'patch', 's', 'short', 'l', 'long', 'a', 'ascii', 'c', 'chars', 't', 'tuple', 'h', 'hash', 'n', 'majmin'],
- /,
Format the version. See the return values below, using version 123.4.0 as example.
x, hex:
'0x7b0400'o, oct:
'0o36602000'b, bin:
'0b11110110000010000000000'd, dec:
'8061952'0, major, maj:'123'1, minor, min:'4'2, patch:'0's, short:
'123.4'l, long:
'asyncutils version 123.4.0'a, ascii:
'{\x04\x00'c, chars:
'{\x04\x00't, tuple:
'(123, 4, 0)'h, hash:
'116380397'n, majmin:
'123.4'
- __getitem__(idx: Literal[0, 1, 2], /) int[source]¶
- __getitem__(idx: asyncutils._internal.prots.ValidSlice, /) tuple[int, Ellipsis]
Return a property depending on the value of
idx.Slicing works as if the version object is a tuple of these three items, which is also accessible as
parts.
- __hash__() int[source]¶
- A perfect hash function for versions! May produce larger integers than
__int__()in some cases, and may also produce negative integers.Sincehash()returns the output of__hash__()modulo0x1FFFFFFFFFFFFFFF(largest Mersenne prime within 64 bits), the reasonable limit for versions that can be hashed and unhashed losslessly lies aroundVersionInfo(46340, 41707, 2147483645).
- __int__() int[source]¶
Assuming
minorandpatchare less than 256, pack the parts into an integer, which can be larger than 24 bits to fit the major version.OverflowErroris raised if not possible.
- __radd__(n: int, /) Self¶
- __radd__(delta: VersionDelta, /) Self
Return this version incremented by
npatches or the deltadelta.
- __round__(ndigits: int, /) NoReturn[source]¶
- __round__(ndigits: Literal[1, 2, 3] | None = ..., /) Self
Support for rounding.
- __setattr__(name: str, value: object, /) NoReturn[source]¶
Disallow modifying attributes of the object.
- __sub__(n: int, /) Self[source]¶
- __sub__(delta: VersionDelta, /) Self
- __sub__(other: Self, /) VersionDelta
Return this version decremented by
npatches or the deltadelta, or the delta betweenselfandother.
- __trunc__() int¶
Identical to
__floor__().
- _replace(major: int = ..., minor: int = ..., patch: int = ...) Self¶
Satisfy the named tuple interface.
- assert_valid() None[source]¶
Signify an error if the user messed something up in this object, likely intentionally.
- change_sep(sep: str) str[source]¶
Return this version as a string with the specified separator instead of a dot between parts.
- compatible(other: Self, /, maj_tol: int | None = ..., min_tol: int | None = ...) bool[source]¶
Whether this version is compatible with the other, given the major and minor tolerances.
- classmethod from_rep(rep: str) Self[source]¶
Parse the string representation of a version to get the version back.
- classmethod get_current_version() Self[source]¶
Return the current version number of
asyncutils; equivalent toasyncutils.__version__.
- is_current_version() bool[source]¶
Whether this version is the same as the current version of
asyncutils.
- replace_parts(*, major: int = ..., minor: int = ..., patch: int = ...) Self[source]¶
Another instance of this class with the specified parts.
- shelve(path: asyncutils._internal.prots.Openable, /, key: int = ...) None[source]¶
Store this version into the specified
path, non-cryptographically transforming the bytes withkey, which can be any integer.
- to_complex() complex[source]¶
Loses the patch version. Since this class is a
strsubclass, an implementation of__complex__()will not be recognized.
- classmethod unshelve(path: asyncutils._internal.prots.Openable, /, key: int = ...) Self[source]¶
Recover a stored version from
path. A wrong key would usually raise an error, and even if it doesn’t, the version would be wrong.
- property next_major: Self¶
The major version following this version, with minor and patch
0.
- property next_minor: Self¶
The minor version following this version, with a patch of
0.
- property next_patch: Self¶
The patch version following this version.
- asyncutils.version.autogenerate_normalizers() bool[source]¶
Register normalizers for
decimal.Decimalandfractions.Fraction. Return whether both normalizers were successfully registered, including re-registration of the same normalizer.
- asyncutils.version.dispatch_normalizer[T](o: type[T], /) collections.abc.Callable[[T], collections.abc.Iterable[int]] | None[source]¶
- asyncutils.version.dispatch_normalizer(o: T, /) collections.abc.Callable[[T], collections.abc.Iterable[int]] | None
Return the normalizer to be used for the object or type.
- asyncutils.version.normalize(o: object, /) tuple[int, int, int][source]¶
- Return a
tupleof three integers(major, minor, patch)from the information provided by the object as extracted by registered normalizers.A normalizer can returnNonefor an unnormalizable object, in which case the comparison operators against instances ofVersionInfowill delegate to the object itself.If the normalizer raises an exception or returns a non-iterable, it is removed and the error is propagated.Note
Normalization logic is hardcoded for exact instances of
str,complex,int, andfloat. This takes precedence over any registered normalizers, but those can still be accessed withdispatch_normalizer().Note
For iterables, the default behaviour is to take the first three items and pad zeros behind if necessary.
- asyncutils.version.normalize_allow_unimplemented(o: object, /) tuple[int, int, int] | None[source]¶
Like
normalize(), but returnsNoneif a normalizer is not found.
- asyncutils.version.register_normalizer[T](o: type[T], f: collections.abc.Callable[[T], collections.abc.Iterable[int]], /) bool[source]¶
- asyncutils.version.register_normalizer(o: T, f: collections.abc.Callable[[T], collections.abc.Iterable[int]], /) bool
Register a custom normalizer for the object or type; return whether the normalizer was newly registered.
- asyncutils.version.unregister_normalizer[T](o: type[T], /) collections.abc.Callable[[T], collections.abc.Iterable[int]] | None[source]¶
- asyncutils.version.unregister_normalizer(o: T, /) collections.abc.Callable[[T], collections.abc.Iterable[int]] | None
Unregister the normalizer for the object or type and return it if any.