Skip to content

Null

Bases: OptionType[T]


              flowchart TD
              pyochain.core._option.Null[Null]
              pyochain.core._option.OptionType[OptionType]
              pyochain.abc._mixins.Pipe[Pipe]

                              pyochain.core._option.OptionType --> pyochain.core._option.Null
                                pyochain.abc._mixins.Pipe --> pyochain.core._option.OptionType
                



              click pyochain.core._option.Null href "" "pyochain.core._option.Null"
              click pyochain.core._option.OptionType href "" "pyochain.core._option.OptionType"
              click pyochain.abc._mixins.Pipe href "" "pyochain.abc._mixins.Pipe"
            

Option variant representing the absence of a value.

This class or NONE can be used interchangeably, as calling Null() will always return the singleton instance NONE.

For pattern matching, you must use Null, as NONE isn't special cased by type checkers the same way python None is, and thus can't be narrowed to Null.

For more documentation, see the Option[T] class.

Example
from pyochain import Null, NONE, Some, Option

assert Null() is NONE

def is_none(x: Option[int]) -> bool:
    match x:
        case Null():
            return True
        case Some(_):
            return False

assert is_none(NONE)
assert not is_none(Some(42))
assert is_none(Null())
Source code in pyochain/core/_option.pyi
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
@final
class Null[T = Any](OptionType[T]):
    """Option variant representing the absence of a value.

    This class or `NONE` can be used interchangeably, as calling `Null()` will always return the singleton instance `NONE`.

    For pattern matching, you must use `Null`, as `NONE` isn't special cased by type checkers the same way python `None` is, and thus can't be narrowed to `Null`.

    For more documentation, see the `Option[T]` class.

    Example:
        ```python
        from pyochain import Null, NONE, Some, Option

        assert Null() is NONE

        def is_none(x: Option[int]) -> bool:
            match x:
                case Null():
                    return True
                case Some(_):
                    return False

        assert is_none(NONE)
        assert not is_none(Some(42))
        assert is_none(Null())
        ```
    """
    def __new__(cls) -> Option[T]: ...