Skip to content

SecretNumber

SecretNumber

Bases: IntegerOps, Secret[N], Integral

A specialized subclass of Secret[IntLike] for holding ints or floats.

This class provides wrappers for every major numeric operation supported by int. Simply call the methods as you would on a regular int. The result will, of course, be another SecretNumber.

Source code in secret_type/containers/number.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class SecretNumber(IntegerOps, Secret[N], Integral, metaclass=SecretNumberMeta):
    """A specialized subclass of [`Secret[IntLike]`][secret_type.Secret] for holding ints or floats.

    This class provides wrappers for every major numeric operation supported by `int`.
    Simply call the methods as you would on a regular `int`.
    The result will, of course, be another `SecretNumber`.
    """

    def __index__(self) -> "SecretNumber[int]":
        raise SecretKeyException()

    def __int__(self) -> "SecretNumber[int]":
        return SecretNumber(int(self._dangerous_extract()))

    def __float__(self) -> "SecretNumber[float]":
        return SecretNumber(float(self._dangerous_extract()))

    def __complex__(self) -> complex:
        raise SecretFloatException()