Skip to content

PyoMapping

Bases: PyoCollection[_K], Mapping[_K, _V_co], Generic[_K, _V_co]


              flowchart TD
              pyochain.abc._mappings.PyoMapping[PyoMapping]
              pyochain.abc._collection.PyoCollection[PyoCollection]
              pyochain.abc._iterable.PyoIterable[PyoIterable]
              pyochain.abc._collection.PyoContainer[PyoContainer]
              pyochain.abc._collection.PyoSized[PyoSized]
              pyochain.abc._mixins.Checkable[Checkable]
              pyochain.abc._mixins.Fluent[Fluent]
              pyochain.abc._mixins.Pipe[Pipe]
              pyochain.abc._mixins.Tap[Tap]

                              pyochain.abc._collection.PyoCollection --> pyochain.abc._mappings.PyoMapping
                                pyochain.abc._iterable.PyoIterable --> pyochain.abc._collection.PyoCollection
                                pyochain.abc._mixins.Checkable --> pyochain.abc._iterable.PyoIterable
                
                pyochain.abc._mixins.Fluent --> pyochain.abc._iterable.PyoIterable
                                pyochain.abc._mixins.Pipe --> pyochain.abc._mixins.Fluent
                
                pyochain.abc._mixins.Tap --> pyochain.abc._mixins.Fluent
                


                pyochain.abc._collection.PyoContainer --> pyochain.abc._collection.PyoCollection
                                pyochain.abc._mixins.Checkable --> pyochain.abc._collection.PyoContainer
                

                pyochain.abc._collection.PyoSized --> pyochain.abc._collection.PyoCollection
                                pyochain.abc._mixins.Checkable --> pyochain.abc._collection.PyoSized
                




              click pyochain.abc._mappings.PyoMapping href "" "pyochain.abc._mappings.PyoMapping"
              click pyochain.abc._collection.PyoCollection href "" "pyochain.abc._collection.PyoCollection"
              click pyochain.abc._iterable.PyoIterable href "" "pyochain.abc._iterable.PyoIterable"
              click pyochain.abc._collection.PyoContainer href "" "pyochain.abc._collection.PyoContainer"
              click pyochain.abc._collection.PyoSized href "" "pyochain.abc._collection.PyoSized"
              click pyochain.abc._mixins.Checkable href "" "pyochain.abc._mixins.Checkable"
              click pyochain.abc._mixins.Fluent href "" "pyochain.abc._mixins.Fluent"
              click pyochain.abc._mixins.Pipe href "" "pyochain.abc._mixins.Pipe"
              click pyochain.abc._mixins.Tap href "" "pyochain.abc._mixins.Tap"
            

Extends PyoCollection[K] and collections.abc.Mapping[K, V].

Serves as a base class for pyochain mappings, such as Dict.

Any concrete subclass must implement the required Mapping dunder methods:

  • __getitem__
  • __iter__
  • __len__
Source code in pyochain/abc/_mappings.pyi
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
class PyoMapping(PyoCollection[_K], Mapping[_K, _V_co], Generic[_K, _V_co]):  # pyright: ignore[reportImplicitAbstractClass]  # ruff:ignore[non-pep695-generic-class]
    """Extends `PyoCollection[K]` and `collections.abc.Mapping[K, V]`.

    Serves as a base class for pyochain mappings, such as `Dict`.

    Any concrete subclass must implement the required `Mapping` dunder methods:

    - `__getitem__`
    - `__iter__`
    - `__len__`
    """

    @abstractmethod
    @override
    def __getitem__(self, key: _K, /) -> _V_co: ...
    @override
    def __contains__(self, key: object, /) -> bool: ...
    @override
    def __eq__(self, other: object, /) -> bool: ...
    @override
    def keys(self) -> PyoKeysView[_K]:
        """Return a view of the `Mapping` keys.

        Returns:
            PyoKeysView[_K]: A view of the dictionary's keys.

        Example:
            ```python
            from pyochain import Dict
            from pyochain.abc import PyoKeysView

            data = Dict(a=1, b=2)
            keys = data.keys()
            assert isinstance(keys, PyoKeysView)
            assert keys.pipe(tuple) == ("a", "b")
            assert repr(keys) == "PyoKeysView(Dict('a': 1, 'b': 2))"
            ```
        """

    @override
    def values(self) -> PyoValuesView[_V_co]:
        """Return a view of the `Mapping` values.

        Returns:
            PyoValuesView[_V_co]: A view of the dictionary's values.

        Example:
            ```python
            from pyochain import Dict
            from pyochain.abc import PyoValuesView

            data = Dict(a=1, b=2)
            values = data.values()
            assert isinstance(values, PyoValuesView)
            assert values.pipe(tuple) == (1, 2)
            assert repr(values) == "PyoValuesView(Dict('a': 1, 'b': 2))"
            ```
        """

    @override
    def items(self) -> PyoItemsView[_K, _V_co]:
        """Return a view of the `Mapping` items.

        Returns:
            PyoItemsView[_K, _V_co]: A view of the dictionary's (key, value) pairs.

        Example:
            ```python
            from pyochain import Dict
            from pyochain.abc import PyoItemsView

            data = Dict(a=1, b=2)
            items = data.items()
            assert isinstance(items, PyoItemsView)
            assert items.pipe(tuple) == (("a", 1), ("b", 2))
            assert repr(items) == "PyoItemsView(Dict('a': 1, 'b': 2))"
            ```
        """

    @overload
    def get(self, key: _K, /) -> _V_co | None: ...
    @overload
    # pyrefly: ignore [invalid-variance]
    def get(
        self,
        key: _K,
        default: _V_co,  # pyright: ignore[reportGeneralTypeIssues]
        /,
    ) -> _V_co: ...
    @overload
    def get[T](self, key: _K, default: T, /) -> _V_co | T: ...
    @override
    def get[T](self, key: _K, default: T | None = None, /) -> _V_co | T | None: ...
    def get_item(self, key: _K) -> Option[_V_co]:
        """Retrieve a value from the `MutableMapping`.

        Returns `Some(value)` if the **key** exists, or `Null` if it does not.

        Args:
            key (_K): The key to look up.

        Returns:
            Option[_V_co]: `Some(value)` that is associated with the **key**, or `Null` if not found.

        Example:
            ```python
            from pyochain import Dict, Some

            data = Dict(a=1)
            item = data.get_item("a")
            assert item == Some(1)
            assert data.get_item("x").unwrap_or("Not Found") == "Not Found"
            ```
        """

keys()

Return a view of the Mapping keys.

Returns:

Type Description
PyoKeysView[_K]

PyoKeysView[_K]: A view of the dictionary's keys.

Example
from pyochain import Dict
from pyochain.abc import PyoKeysView

data = Dict(a=1, b=2)
keys = data.keys()
assert isinstance(keys, PyoKeysView)
assert keys.pipe(tuple) == ("a", "b")
assert repr(keys) == "PyoKeysView(Dict('a': 1, 'b': 2))"
Source code in pyochain/abc/_mappings.pyi
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
@override
def keys(self) -> PyoKeysView[_K]:
    """Return a view of the `Mapping` keys.

    Returns:
        PyoKeysView[_K]: A view of the dictionary's keys.

    Example:
        ```python
        from pyochain import Dict
        from pyochain.abc import PyoKeysView

        data = Dict(a=1, b=2)
        keys = data.keys()
        assert isinstance(keys, PyoKeysView)
        assert keys.pipe(tuple) == ("a", "b")
        assert repr(keys) == "PyoKeysView(Dict('a': 1, 'b': 2))"
        ```
    """

values()

Return a view of the Mapping values.

Returns:

Type Description
PyoValuesView[_V_co]

PyoValuesView[_V_co]: A view of the dictionary's values.

Example
from pyochain import Dict
from pyochain.abc import PyoValuesView

data = Dict(a=1, b=2)
values = data.values()
assert isinstance(values, PyoValuesView)
assert values.pipe(tuple) == (1, 2)
assert repr(values) == "PyoValuesView(Dict('a': 1, 'b': 2))"
Source code in pyochain/abc/_mappings.pyi
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
@override
def values(self) -> PyoValuesView[_V_co]:
    """Return a view of the `Mapping` values.

    Returns:
        PyoValuesView[_V_co]: A view of the dictionary's values.

    Example:
        ```python
        from pyochain import Dict
        from pyochain.abc import PyoValuesView

        data = Dict(a=1, b=2)
        values = data.values()
        assert isinstance(values, PyoValuesView)
        assert values.pipe(tuple) == (1, 2)
        assert repr(values) == "PyoValuesView(Dict('a': 1, 'b': 2))"
        ```
    """

items()

Return a view of the Mapping items.

Returns:

Type Description
PyoItemsView[_K, _V_co]

PyoItemsView[_K, _V_co]: A view of the dictionary's (key, value) pairs.

Example
from pyochain import Dict
from pyochain.abc import PyoItemsView

data = Dict(a=1, b=2)
items = data.items()
assert isinstance(items, PyoItemsView)
assert items.pipe(tuple) == (("a", 1), ("b", 2))
assert repr(items) == "PyoItemsView(Dict('a': 1, 'b': 2))"
Source code in pyochain/abc/_mappings.pyi
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
@override
def items(self) -> PyoItemsView[_K, _V_co]:
    """Return a view of the `Mapping` items.

    Returns:
        PyoItemsView[_K, _V_co]: A view of the dictionary's (key, value) pairs.

    Example:
        ```python
        from pyochain import Dict
        from pyochain.abc import PyoItemsView

        data = Dict(a=1, b=2)
        items = data.items()
        assert isinstance(items, PyoItemsView)
        assert items.pipe(tuple) == (("a", 1), ("b", 2))
        assert repr(items) == "PyoItemsView(Dict('a': 1, 'b': 2))"
        ```
    """

get_item(key)

Retrieve a value from the MutableMapping.

Returns Some(value) if the key exists, or Null if it does not.

Parameters:

Name Type Description Default
key _K

The key to look up.

required

Returns:

Type Description
Option[_V_co]

Option[_V_co]: Some(value) that is associated with the key, or Null if not found.

Example
from pyochain import Dict, Some

data = Dict(a=1)
item = data.get_item("a")
assert item == Some(1)
assert data.get_item("x").unwrap_or("Not Found") == "Not Found"
Source code in pyochain/abc/_mappings.pyi
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def get_item(self, key: _K) -> Option[_V_co]:
    """Retrieve a value from the `MutableMapping`.

    Returns `Some(value)` if the **key** exists, or `Null` if it does not.

    Args:
        key (_K): The key to look up.

    Returns:
        Option[_V_co]: `Some(value)` that is associated with the **key**, or `Null` if not found.

    Example:
        ```python
        from pyochain import Dict, Some

        data = Dict(a=1)
        item = data.get_item("a")
        assert item == Some(1)
        assert data.get_item("x").unwrap_or("Not Found") == "Not Found"
        ```
    """