Skip to content

sob.types

NULL module-attribute

NULL: sob._types.Null = sob._types.Null()

sob.NULL is the singleton instance of sob.Null, and is used to represent an explicit null value in JSON, whereas in the context of an instance of a sub-class of sob.ObjectNone indicates the absence of a property value.

UNDEFINED module-attribute

UNDEFINED: sob._types.Undefined = sob._types.Undefined()

sob.UNDEFINED is the singleton instance of sob.Undefined, and is used to indicate that a parameter has not been passed to a function or method keyword.

Null

Null()

Instances of this class represent an explicit null value, rather than the absence of a property/attribute/element, as would be inferred from a value of None.

Note: Like the built-in value None, only one instance of this class is permitted (it's a singleton), so this class should never be instantiated, it should always be referenced through the constant sob.NULL.

Source code in src/sob/_types.py
90
91
92
93
def __init__(self) -> None:
    if "NULL" in _module_locals:
        message: str = f"{self!r} may only be defined once."
        raise DefinitionExistsError(message)

Undefined

Undefined()

This class is intended to indicate that a parameter has not been passed to a keyword argument in situations where None is to be used as a meaningful value.

The Undefined class is a singleton, so only one instance of this class is permitted: sob.UNDEFINED.

Source code in src/sob/_types.py
24
25
26
27
28
29
def __init__(self) -> None:
    # Only one instance of `Undefined` is permitted, so initialization
    # checks to make sure this is the first use.
    if "UNDEFINED" in _module_locals:
        message: str = f"{self!r} may only be instantiated once."
        raise DefinitionExistsError(message)

Types

Types(
    items: (
        sob.abc.Types
        | collections.abc.Iterable[type | sob.abc.Property]
        | type
        | sob.abc.Property
        | None
    ) = None,
)

Bases: sob.abc.Types

Instances of this class are immutable lists of types and/or property definitions.

Source code in src/sob/types.py
34
35
36
37
38
39
40
41
42
43
44
45
46
def __init__(
    self,
    items: abc.Types
    | Iterable[type | abc.Property]
    | type
    | abc.Property
    | None = None,
) -> None:
    if isinstance(items, (type, abc.Property)):
        items = (items,)
    self._list: list[type | abc.Property] = []
    if items is not None:
        self._extend(items)

MutableTypes

MutableTypes(
    items: (
        sob.abc.Types
        | collections.abc.Iterable[type | sob.abc.Property]
        | type
        | sob.abc.Property
        | None
    ) = None,
)

Bases: sob.types.Types, sob.abc.MutableTypes

Instances of this class are (mutable) lists of types and/or property definitions.

Source code in src/sob/types.py
34
35
36
37
38
39
40
41
42
43
44
45
46
def __init__(
    self,
    items: abc.Types
    | Iterable[type | abc.Property]
    | type
    | abc.Property
    | None = None,
) -> None:
    if isinstance(items, (type, abc.Property)):
        items = (items,)
    self._list: list[type | abc.Property] = []
    if items is not None:
        self._extend(items)