diff --git a/dag_cbor/__init__.py b/dag_cbor/__init__.py
index 45a2a55..8549738 100644
--- a/dag_cbor/__init__.py
+++ b/dag_cbor/__init__.py
@@ -4,12 +4,11 @@
from __future__ import annotations # See https://peps.python.org/pep-0563/
-__version__ = "0.3.0"
+__version__ = "0.3.1"
-from . import ipld
-from .ipld import Kind, Path
+from .ipld import IPLDKind, IPLDScalarKind, ObjPath
from .encoding import encode
from .decoding import decode
# explicit re-exports
-__all__ = ["encode", "decode", "ipld", "Kind", "Path"]
+__all__ = ["encode", "decode", "IPLDKind", "IPLDScalarKind", "ObjPath"]
diff --git a/dag_cbor/decoding/__init__.py b/dag_cbor/decoding/__init__.py
index 6792fae..c1312d8 100644
--- a/dag_cbor/decoding/__init__.py
+++ b/dag_cbor/decoding/__init__.py
@@ -15,7 +15,7 @@
from multiformats import multicodec, CID, varint
-from ..ipld import Kind
+from ..ipld import IPLDKind
from ..encoding import _dag_cbor_code
from .err import CBORDecodingError, DAGCBORDecodingError
from . import _err
@@ -27,7 +27,7 @@ class DecodeCallback(Protocol):
r"""
Type of optional callbacks for the :func:`decode` function.
"""
- def __call__(self, value: Kind, num_bytes_read: int) -> None:
+ def __call__(self, value: IPLDKind, num_bytes_read: int) -> None:
...
class _DecodeOptions(TypedDict, total=False):
@@ -43,7 +43,7 @@ def decode(stream_or_bytes: Union[BufferedIOBase, bytes], *,
allow_concat: bool = False,
callback: Optional["DecodeCallback"] = None,
require_multicodec: bool = False,
- normalize_strings: Literal["NFC", "NFKC", "NFD", "NFKD", None] = None) -> Kind:
+ normalize_strings: Literal["NFC", "NFKC", "NFD", "NFKD", None] = None) -> IPLDKind:
r"""
Decodes and returns a single data item from the given ``stream_or_bytes``, with the DAG-CBOR codec.
@@ -131,9 +131,9 @@ def decode(stream_or_bytes: Union[BufferedIOBase, bytes], *,
raise DAGCBORDecodingError(_err._multiple_top_level_items(stream))
return data
-def _decode_item(stream: Stream, options: _DecodeOptions) -> Tuple[Kind, int]:
+def _decode_item(stream: Stream, options: _DecodeOptions) -> Tuple[IPLDKind, int]:
major_type, arg, num_bytes_read = _decode_head(stream)
- ret: Optional[Tuple[Kind, int]] = None
+ ret: Optional[Tuple[IPLDKind, int]] = None
assert 0x0 <= major_type <= 0x7, f"Major type must be one of 0x0-0x7, found 0x{major_type:x} instead."
if isinstance(arg, float):
# Major type 0x7 (float case):
@@ -234,7 +234,7 @@ def _decode_list(stream: Stream, length: int, options: _DecodeOptions) -> Tuple[
def _decode_dict_key(stream: Stream, key_idx: int, dict_length: int, options: _DecodeOptions) -> Tuple[str, int, bytes]:
# pylint: disable = too-many-return-statements, too-many-branches
major_type, arg, num_bytes_read = _decode_head(stream)
- ret: Optional[Tuple[Kind, int]] = None
+ ret: Optional[Tuple[IPLDKind, int]] = None
if major_type != 0x3:
raise DAGCBORDecodingError(_err._dict_key_type(stream, major_type))
assert not isinstance(arg, float)
@@ -309,7 +309,7 @@ def _decode_bool_none(stream: Stream, arg: int, options: _DecodeOptions) -> Tupl
def _decode_dummy(stream: Stream, arg: int, options: _DecodeOptions) -> Tuple[None, int]:
assert False, f"Major type {arg} does not have an associated decoder."
-_decoders: Tuple[Callable[[Stream, int, _DecodeOptions], Tuple[Kind, int]], ...] = (
+_decoders: Tuple[Callable[[Stream, int, _DecodeOptions], Tuple[IPLDKind, int]], ...] = (
_decode_dummy,
_decode_dummy,
_decode_bytes,
diff --git a/dag_cbor/decoding/_err.py b/dag_cbor/decoding/_err.py
index e29330e..4d38943 100644
--- a/dag_cbor/decoding/_err.py
+++ b/dag_cbor/decoding/_err.py
@@ -10,7 +10,7 @@
from multiformats import varint
-from ..ipld import Kind
+from ..ipld import IPLDKind
from ..encoding import _dag_cbor_code
from .err import CBORDecodingError
from ._stream import Stream, StreamSnapshot
@@ -139,7 +139,7 @@ def _invalid_tag(stream: Stream, arg: int) -> str:
def _cid(cid_head_snapshots: Tuple[StreamSnapshot, StreamSnapshot], e: CBORDecodingError) -> str:
return _cid_error_template(cid_head_snapshots, *_extract_error_cause_lines(e))
-def _cid_bytes(cid_head_snapshots: Tuple[StreamSnapshot, StreamSnapshot], stream: Stream, cid_bytes: Kind) -> str:
+def _cid_bytes(cid_head_snapshots: Tuple[StreamSnapshot, StreamSnapshot], stream: Stream, cid_bytes: IPLDKind) -> str:
decoded_type = type(cid_bytes).__name__
details = f"decodes to an item of type {repr(decoded_type)}"
explanation = [
diff --git a/dag_cbor/encoding/__init__.py b/dag_cbor/encoding/__init__.py
index 6a78872..6a26d72 100644
--- a/dag_cbor/encoding/__init__.py
+++ b/dag_cbor/encoding/__init__.py
@@ -15,7 +15,7 @@
from multiformats import varint, multicodec, CID
-from ..ipld import Kind, Path
+from ..ipld import IPLDKind, ObjPath
from .err import CBOREncodingError, DAGCBOREncodingError
__all__ = ("CBOREncodingError", "DAGCBOREncodingError")
@@ -44,20 +44,20 @@ def canonical_order_dict(value: Dict[str, Any]) -> Dict[str, Any]:
@overload
-def encode(data: Kind, stream: None = None, *,
+def encode(data: IPLDKind, stream: None = None, *,
include_multicodec: bool = False,
normalize_strings: Optional[Literal["NFC", "NFKC", "NFD", "NFKD"]] = None
) -> bytes:
... # pragma: no cover
@overload
-def encode(data: Kind, stream: BufferedIOBase, *,
+def encode(data: IPLDKind, stream: BufferedIOBase, *,
include_multicodec: bool = False,
normalize_strings: Optional[Literal["NFC", "NFKC", "NFD", "NFKD"]] = None
) -> int:
... # pragma: no cover
-def encode(data: Kind, stream: Optional[BufferedIOBase] = None, *,
+def encode(data: IPLDKind, stream: Optional[BufferedIOBase] = None, *,
include_multicodec: bool = False,
normalize_strings: Optional[Literal["NFC", "NFKC", "NFD", "NFKD"]] = None
) -> Union[bytes, int]:
@@ -68,7 +68,7 @@ def encode(data: Kind, stream: Optional[BufferedIOBase] = None, *,
.. code-block:: python
- def encode(data: Kind, stream: None = None) -> bytes:
+ def encode(data: IPLDKind, stream: None = None) -> bytes:
...
Example usage:
@@ -80,7 +80,7 @@ def encode(data: Kind, stream: None = None) -> bytes:
.. code-block:: python
- def encode(data: Kind, stream: BufferedIOBase) -> int:
+ def encode(data: IPLDKind, stream: BufferedIOBase) -> int:
...
Example usage with a stream:
@@ -111,7 +111,7 @@ def encode(data: Kind, stream: BufferedIOBase) -> int:
if normalize_strings is not None:
validate(normalize_strings, Literal["NFC", "NFKC", "NFD", "NFKD"])
options["normalize_strings"] = normalize_strings
- path = Path()
+ path = ObjPath()
if stream is None:
internal_stream = BytesIO()
if include_multicodec:
@@ -131,7 +131,7 @@ class _EncodeOptions(TypedDict, total=False):
normalize_strings: Literal["NFC", "NFKC", "NFD", "NFKD"]
r""" Optional Unicode normalization to be performed on UTF-8 strings prior to byte encoding. """
-def _encode(stream: BufferedIOBase, value: Kind, path: Path, options: _EncodeOptions) -> int:
+def _encode(stream: BufferedIOBase, value: IPLDKind, path: ObjPath, options: _EncodeOptions) -> int:
# pylint: disable = too-many-return-statements, too-many-branches
if isinstance(value, bool): # must go before int check
# major type 0x7 (additional info 20 and 21)
@@ -182,7 +182,7 @@ def _encode_head(stream: BufferedIOBase, major_type: int, arg: int) -> int:
stream.write(head)
return len(head)
-def _encode_int(stream: BufferedIOBase, value: int, path: Path, options: _EncodeOptions) -> int:
+def _encode_int(stream: BufferedIOBase, value: int, path: ObjPath, options: _EncodeOptions) -> int:
if value >= 18446744073709551616:
# unsigned int must be < 2**64
err = f"Error encoding integer value at {path}: Unsigned integer out of range."
@@ -197,12 +197,12 @@ def _encode_int(stream: BufferedIOBase, value: int, path: Path, options: _Encode
# negative int
return _encode_head(stream, 0x1, -1-value)
-def _encode_bytes(stream: BufferedIOBase, value: bytes, path: Path, options: _EncodeOptions) -> int:
+def _encode_bytes(stream: BufferedIOBase, value: bytes, path: ObjPath, options: _EncodeOptions) -> int:
num_head_bytes = _encode_head(stream, 0x2, len(value))
stream.write(value)
return num_head_bytes+len(value)
-def _encode_str(stream: BufferedIOBase, value: str, path: Path, options: _EncodeOptions) -> int:
+def _encode_str(stream: BufferedIOBase, value: str, path: ObjPath, options: _EncodeOptions) -> int:
if "normalize_strings" in options:
value = unicodedata.normalize(options["normalize_strings"], value)
utf8_value: bytes = value.encode("utf-8", errors="strict")
@@ -210,13 +210,13 @@ def _encode_str(stream: BufferedIOBase, value: str, path: Path, options: _Encode
stream.write(utf8_value)
return num_head_bytes+len(utf8_value)
-def _encode_list(stream: BufferedIOBase, value: List[Any], path: Path, options: _EncodeOptions) -> int:
+def _encode_list(stream: BufferedIOBase, value: List[Any], path: ObjPath, options: _EncodeOptions) -> int:
num_bytes_written = _encode_head(stream, 0x4, len(value))
for idx, item in enumerate(value):
num_bytes_written += _encode(stream, item, path/idx, options)
return num_bytes_written
-def _encode_dict(stream: BufferedIOBase, value: Dict[str, Any], path: Path, options: _EncodeOptions) -> int:
+def _encode_dict(stream: BufferedIOBase, value: Dict[str, Any], path: ObjPath, options: _EncodeOptions) -> int:
_check_key_compliance(value, path)
if "normalize_strings" in options:
nf = options["normalize_strings"]
@@ -234,18 +234,18 @@ def _encode_dict(stream: BufferedIOBase, value: Dict[str, Any], path: Path, opti
num_bytes_written += _encode(stream, v, path/k, options)
return num_bytes_written
-def _encode_cid(stream: BufferedIOBase, value: CID, path: Path, options: _EncodeOptions) -> int:
+def _encode_cid(stream: BufferedIOBase, value: CID, path: ObjPath, options: _EncodeOptions) -> int:
num_bytes_written = _encode_head(stream, 0x6, 42)
num_bytes_written += _encode_bytes(stream, b"\0" + bytes(value), path, options)
return num_bytes_written
-def _encode_bool(stream: BufferedIOBase, value: bool, path: Path, options: _EncodeOptions) -> int:
+def _encode_bool(stream: BufferedIOBase, value: bool, path: ObjPath, options: _EncodeOptions) -> int:
return _encode_head(stream, 0x7, 21 if value else 20)
-def _encode_none(stream: BufferedIOBase, value: None, path: Path, options: _EncodeOptions) -> int:
+def _encode_none(stream: BufferedIOBase, value: None, path: ObjPath, options: _EncodeOptions) -> int:
return _encode_head(stream, 0x7, 22)
-def _encode_float(stream: BufferedIOBase, value: float, path: Path, options: _EncodeOptions) -> int:
+def _encode_float(stream: BufferedIOBase, value: float, path: ObjPath, options: _EncodeOptions) -> int:
if math.isnan(value):
err = f"Error encoding float value at {path}: NaN is not allowed."
raise DAGCBOREncodingError(err)
@@ -258,7 +258,7 @@ def _encode_float(stream: BufferedIOBase, value: float, path: Path, options: _En
stream.write(head)
return len(head)
-def _check_key_compliance(value: Dict[str, Any], path: Optional[Path] = None) -> None:
+def _check_key_compliance(value: Dict[str, Any], path: Optional[ObjPath] = None) -> None:
""" Check keys for DAG-CBOR compliance. """
for idx, k in enumerate(value.keys()):
if not isinstance(k, str):
diff --git a/dag_cbor/ipld.py b/dag_cbor/ipld.py
index c2c2ae7..cf56aca 100644
--- a/dag_cbor/ipld.py
+++ b/dag_cbor/ipld.py
@@ -29,7 +29,7 @@
from multiformats import CID
-ScalarKind = Union[None, bool, int, float, str, bytes, CID]
+IPLDScalarKind = Union[None, bool, int, float, str, bytes, CID]
r"""
Python type alias for scalar `kinds `_ in the IPLD data model:
@@ -43,7 +43,7 @@
"""
-Kind = Union[ScalarKind, List["Kind"], Dict[str, "Kind"]]
+IPLDKind = Union[IPLDScalarKind, List["IPLDKind"], Dict[str, "IPLDKind"]]
r"""
Python type alias for `kinds `_ in the IPLD data model:
@@ -59,39 +59,39 @@
"""
-Segment = Union[int, str]
+ObjPathSegment = Union[int, str]
r"""
- An individual segment in a :class:`Path` within a IPLD value (see :obj:`Kind` for the ). A segment can be an :obj:`int` or a :obj:`str`:
+ An individual segment in a :class:`ObjPath` within a IPLD value (see :obj:`IPLDKind` for the ). A segment can be an :obj:`int` or a :obj:`str`:
- - an :obj:`int` segment is a position, indexing an item in a value of List :obj:`Kind` (a :obj:`List` in Python)
- - an :obj:`str` segment is a key, indexing a value in a value of Map :obj:`Kind` (a :obj:`Dict` in Python)
+ - an :obj:`int` segment is a position, indexing an item in a value of List :obj:`IPLDKind` (a :obj:`List` in Python)
+ - an :obj:`str` segment is a key, indexing a value in a value of Map :obj:`IPLDKind` (a :obj:`Dict` in Python)
"""
-_Segments = Tuple[Segment, ...]
+_ObjPathSegments = Tuple[ObjPathSegment, ...]
r"""
Short type alias for multiple segments.
"""
-class Path(Sequence[Segment]):
+class ObjPath(Sequence[ObjPathSegment]):
r"""
- Path within an object of :obj:`Kind`, as a sequence of :obj:`Segment`.
+ Path within an object of :obj:`IPLDKind`, as a sequence of :obj:`ObjPathSegment`.
Paths are immutable and hashable, and a path is a :obj:`Sequence` of the segments that constitute it.
"""
- _instances: ClassVar[MutableMapping[_Segments, Path]] = WeakValueDictionary()
+ _instances: ClassVar[MutableMapping[_ObjPathSegments, ObjPath]] = WeakValueDictionary()
@staticmethod
- def parse(path_str: str) -> Path:
+ def parse(path_str: str) -> ObjPath:
r"""
- Parses a :class:`Path` from a string representation where segments are separated by `"/"`, such as that returned by
- :meth:`Path.__repr__`.
+ Parses a :class:`ObjPath` from a string representation where segments are separated by `"/"`, such as that returned by
+ :meth:`ObjPath.__repr__`.
"""
- if path_str.startswith("Path()"):
+ if path_str.startswith("ObjPath()"):
path_str = path_str[6:]
if not path_str.startswith("/"):
- raise ValueError("Path must start with '/' or 'Path()/'.")
- segs: List[Segment] = []
+ raise ValueError("Path must start with '/' or 'ObjPath()/'.")
+ segs: List[ObjPathSegment] = []
seg_str_list = path_str[1:].split("/")
for idx, seg_str in enumerate(seg_str_list):
if seg_str.startswith("'"):
@@ -106,39 +106,39 @@ def parse(path_str: str) -> Path:
if not seg_str.isnumeric():
raise ValueError(f"At segment {idx}: segment is unquoted and not numeric.")
segs.append(int(seg_str))
- return Path._new_instance(tuple(segs))
+ return ObjPath._new_instance(tuple(segs))
@staticmethod
- def _new_instance(segments: Tuple[Segment, ...]) -> Path:
+ def _new_instance(segments: Tuple[ObjPathSegment, ...]) -> ObjPath:
r"""
- Returns an instance of :class:`Path` with given segments, without performing any validation.
+ Returns an instance of :class:`ObjPath` with given segments, without performing any validation.
"""
- instance = Path._instances.get(segments)
+ instance = ObjPath._instances.get(segments)
if instance is None:
- instance = object.__new__(Path)
+ instance = object.__new__(ObjPath)
instance._segments = segments
- Path._instances[segments] = instance
+ ObjPath._instances[segments] = instance
return instance
- _segments: _Segments
+ _segments: _ObjPathSegments
- def __new__(cls, *segments: Segment) -> Path:
- r""" Constructor for :class:`Path`. """
- validate(segments, _Segments)
- return Path._new_instance(segments)
+ def __new__(cls, *segments: ObjPathSegment) -> ObjPath:
+ r""" Constructor for :class:`ObjPath`. """
+ validate(segments, _ObjPathSegments)
+ return ObjPath._new_instance(segments)
- def access(self, value: Kind) -> Kind:
+ def access(self, value: IPLDKind) -> IPLDKind:
r"""
Accesses the sub-value at this path in the given IPLD value.
- Can be written more expressively as `self >> value`, see :meth:`Path.__rshift__`.
+ Can be written more expressively as `self >> value`, see :meth:`ObjPath.__rshift__`.
"""
return _access(self, value)
- def __truediv__(self, other: Union[Segment, Path]) -> Path:
+ def __truediv__(self, other: Union[ObjPathSegment, ObjPath]) -> ObjPath:
r"""
The `/` operator can be used to create paths by concatenating segments. Below we use `_` as a suggestive name for an empty path, acting as root:
- >>> _ = Path()
+ >>> _ = ObjPath()
>>> p = _/2/'red'
>>> p
/2/'red'
@@ -157,16 +157,16 @@ def __truediv__(self, other: Union[Segment, Path]) -> Path:
/2/'red'/0/'blue'
"""
if isinstance(other, (int, str)):
- return Path._new_instance(self._segments+(other,))
- if isinstance(other, Path):
- return Path._new_instance(self._segments+other._segments)
+ return ObjPath._new_instance(self._segments+(other,))
+ if isinstance(other, ObjPath):
+ return ObjPath._new_instance(self._segments+other._segments)
return NotImplemented
- def __rtruediv__(self, other: Union[Segment, Path]) -> Path:
+ def __rtruediv__(self, other: Union[ObjPathSegment, ObjPath]) -> ObjPath:
r"""
It is possible to prepend a single segment at a time to an existing path using `/` (a new path is returned):
- >>> _ = Path()
+ >>> _ = ObjPath()
>>> p = _/2/'red'
>>> 1/p
/1/2/'red'
@@ -177,33 +177,33 @@ def __rtruediv__(self, other: Union[Segment, Path]) -> Path:
/0/1/2/'red'
"""
if isinstance(other, (int, str)):
- return Path._new_instance((other,)+self._segments)
+ return ObjPath._new_instance((other,)+self._segments)
return NotImplemented
def __len__(self) -> int:
return len(self._segments)
- def __iter__(self) -> Iterator[Segment]:
+ def __iter__(self) -> Iterator[ObjPathSegment]:
return iter(self._segments)
@overload
- def __getitem__(self, idx: int) -> Segment:
+ def __getitem__(self, idx: int) -> ObjPathSegment:
...
@overload
- def __getitem__(self, idx: slice) -> Path:
+ def __getitem__(self, idx: slice) -> ObjPath:
...
- def __getitem__(self, idx: Union[int, slice]) -> Union[Segment, Path]:
+ def __getitem__(self, idx: Union[int, slice]) -> Union[ObjPathSegment, ObjPath]:
if isinstance(idx, int):
return self._segments[idx]
- return Path._new_instance(self._segments[idx])
+ return ObjPath._new_instance(self._segments[idx])
- def __le__(self, other: Path) -> bool:
+ def __le__(self, other: ObjPath) -> bool:
r"""
The `<` and `<=` operators can be used to check whether a path is a (strict) sub-path of another path, starting at the same root:
- >>> _ = Path()
+ >>> _ = ObjPath()
>>> p = _/0/'red'
>>> q = p/1/2
>>> p == q
@@ -214,13 +214,13 @@ def __le__(self, other: Path) -> bool:
True
"""
- if isinstance(other, Path):
+ if isinstance(other, ObjPath):
return len(self) <= len(other) and all(a == b for a, b in zip(self, other))
return NotImplemented
- def __lt__(self, other: Path) -> bool:
- r""" See :meth:`Path.__le__`. """
- if isinstance(other, Path):
+ def __lt__(self, other: ObjPath) -> bool:
+ r""" See :meth:`ObjPath.__le__`. """
+ if isinstance(other, ObjPath):
return len(self) < len(other) and all(a == b for a, b in zip(self, other))
return NotImplemented
@@ -232,11 +232,11 @@ def __repr__(self) -> str:
"""
return "/"+"/".join(repr(seg) for seg in self)
- def __rshift__(self, value: Kind) -> Kind:
+ def __rshift__(self, value: IPLDKind) -> IPLDKind:
r"""
Accesses the sub-value at this path in the given IPLD value:
- >>> _ = Path()
+ >>> _ = ObjPath()
>>> _ >> [0, False, {"a": b"hello", "b": "bye"}]
[0, False, {'a': b'hello', 'b': 'bye'}]
>>> _/2 >> [0, False, {"a": b"hello", "b": "bye"}]
@@ -244,12 +244,12 @@ def __rshift__(self, value: Kind) -> Kind:
>>> _/2/'b' >> [0, False, {"a": b"hello", "b": "bye"}]
'bye'
- :raises ValueError: if attempting to access a sub-value in a value of :obj:`ScalarKind`
- :raises ValueError: if attempting to access a sub-value indexed by a :obj:`str` segment in a value of list :obj:`Kind` (a Python :obj:`List`)
- :raises ValueError: if attempting to access a sub-value keyed by a :obj:`int` segment in a value of map :obj:`Kind` (a Python :obj:`Dict`)
+ :raises ValueError: if attempting to access a sub-value in a value of :obj:`IPLDScalarKind`
+ :raises ValueError: if attempting to access a sub-value indexed by a :obj:`str` segment in a value of list :obj:`IPLDKind` (a Python :obj:`List`)
+ :raises ValueError: if attempting to access a sub-value keyed by a :obj:`int` segment in a value of map :obj:`IPLDKind` (a Python :obj:`Dict`)
:raises IndexError: if attempting to access a sub-value in a value of list kind, where the :obj:`int` segment is not a valid index for the list
:raises KeyError: if attempting to access a sub-value in a value of map kind, where the :obj:`str` segment is not a valid key for the map
- :raises TypeError: if any of the sub-values along the path is not of IPLD :obj:`Kind` at the top level
+ :raises TypeError: if any of the sub-values along the path is not of IPLD :obj:`IPLDKind` at the top level
"""
return _access(self, value)
@@ -257,9 +257,9 @@ def __rshift__(self, value: Kind) -> Kind:
_scalar_kinds = (type(None), bool, int, float, str, bytes, CID)
_recursive_kinds = (list, dict)
-def _access(path: Path, value: Kind, idx: int = 0) -> Kind:
+def _access(path: ObjPath, value: IPLDKind, idx: int = 0) -> IPLDKind:
r"""
- Implementation for :func:`Path.access` and :func:`Path.__rshift__`.
+ Implementation for :func:`ObjPath.access` and :func:`ObjPath.__rshift__`.
"""
if isinstance(value, _scalar_kinds):
if len(path) > idx:
diff --git a/dag_cbor/random.py b/dag_cbor/random.py
index 039967f..8f1852a 100644
--- a/dag_cbor/random.py
+++ b/dag_cbor/random.py
@@ -15,7 +15,7 @@
from multiformats import multicodec, multibase, multihash, CID
-from .ipld import Kind
+from .ipld import IPLDKind
from .encoding import encode, _canonical_order_dict
_min_int = -18446744073709551616
@@ -251,7 +251,7 @@ def set_options(*,
_options = _new_options
-def rand_data(n: Optional[int] = None, *, max_nesting: Optional[int] = None) -> Iterator[Kind]:
+def rand_data(n: Optional[int] = None, *, max_nesting: Optional[int] = None) -> Iterator[IPLDKind]:
r"""
Generates a stream of random data.
@@ -269,7 +269,7 @@ def rand_data(n: Optional[int] = None, *, max_nesting: Optional[int] = None) ->
validate(max_nesting, Optional[int])
return _rand_data(n, max_nesting=max_nesting)
-def _rand_data(n: Optional[int] = None, *, max_nesting: Optional[int] = None) -> Iterator[Kind]:
+def _rand_data(n: Optional[int] = None, *, max_nesting: Optional[int] = None) -> Iterator[IPLDKind]:
if n is not None and n < 0:
raise ValueError()
if max_nesting is None:
@@ -548,7 +548,7 @@ def _rand_float(n: Optional[int] = None) -> Iterator[float]:
_cid_multicodec = multicodec.get("dag-cbor")
_cid_multihash = multihash.get("sha3-512")
-def rand_data_cid(n: Optional[int] = None, *, max_nesting: Optional[int] = None) -> Iterator[Tuple[Kind, CID]]:
+def rand_data_cid(n: Optional[int] = None, *, max_nesting: Optional[int] = None) -> Iterator[Tuple[IPLDKind, CID]]:
r"""
Generates a stream of random DAG-CBOR data and associated CIDs:
@@ -582,7 +582,7 @@ def rand_cid(n: Optional[int] = None, *, max_nesting: Optional[int] = None) -> I
def _rand_cid(n: Optional[int] = None, *, max_nesting: Optional[int] = None) -> Iterator[CID]:
return (cid for _, cid in _rand_data_cid(n, max_nesting=max_nesting))
-def _rand_data_cid(n: Optional[int] = None, *, max_nesting: Optional[int] = None) -> Iterator[Tuple[Kind, CID]]:
+def _rand_data_cid(n: Optional[int] = None, *, max_nesting: Optional[int] = None) -> Iterator[Tuple[IPLDKind, CID]]:
if n is not None and n < 0:
raise ValueError()
if max_nesting is None:
diff --git a/docs/api/dag_cbor.ipld.rst b/docs/api/dag_cbor.ipld.rst
index 8440b72..3ab0e22 100644
--- a/docs/api/dag_cbor.ipld.rst
+++ b/docs/api/dag_cbor.ipld.rst
@@ -3,25 +3,25 @@ dag_cbor.ipld
.. automodule:: dag_cbor.ipld
-Kind
-----
+IPLDKind
+--------
-.. autodata:: dag_cbor.ipld.Kind
+.. autodata:: dag_cbor.ipld.IPLDKind
-Path
-----
+IPLDScalarKind
+--------------
-.. autoclass:: dag_cbor.ipld.Path
+.. autodata:: dag_cbor.ipld.IPLDScalarKind
+
+ObjPath
+-------
+
+.. autoclass:: dag_cbor.ipld.ObjPath
:show-inheritance:
:members:
:special-members: __new__, __truediv__, __rtruediv__, __le__, __lt__, __repr__, __rshift__
-ScalarKind
-----------
-
-.. autodata:: dag_cbor.ipld.ScalarKind
-
-Segment
--------
+ObjPathSegment
+--------------
-.. autodata:: dag_cbor.ipld.Segment
+.. autodata:: dag_cbor.ipld.ObjPathSegment
diff --git a/docs/api/dag_cbor.rst b/docs/api/dag_cbor.rst
index a5bd317..d7b5a5d 100644
--- a/docs/api/dag_cbor.rst
+++ b/docs/api/dag_cbor.rst
@@ -8,8 +8,8 @@ dag_cbor.__all__
The following members were explicitly reexported using ``__all__``:
- - :py:obj:`dag_cbor.ipld.Kind`
- - :py:class:`dag_cbor.ipld.Path`
+ - :py:obj:`dag_cbor.ipld.IPLDKind`
+ - :py:obj:`dag_cbor.ipld.IPLDScalarKind`
+ - :py:class:`dag_cbor.ipld.ObjPath`
- :py:func:`dag_cbor.decoding.decode`
- :py:func:`dag_cbor.encoding.encode`
- - :py:mod:`dag_cbor.ipld`
diff --git a/docs/autodoc-type-aliases.json b/docs/autodoc-type-aliases.json
index d0c49f5..4760da0 100644
--- a/docs/autodoc-type-aliases.json
+++ b/docs/autodoc-type-aliases.json
@@ -1,7 +1,7 @@
{
"DecodeCallback": "dag_cbor.decoding.DecodeCallback",
- "ScalarKind": "dag_cbor.ipld.ScalarKind",
- "Kind": "dag_cbor.ipld.Kind",
- "Path": "dag_cbor.ipld.Path",
- "Segment": "dag_cbor.ipld.Segment"
+ "IPLDScalarKind": "dag_cbor.ipld.IPLDScalarKind",
+ "IPLDKind": "dag_cbor.ipld.IPLDKind",
+ "ObjPath": "dag_cbor.ipld.ObjPath",
+ "ObjPathSegment": "dag_cbor.ipld.ObjPathSegment"
}
\ No newline at end of file
diff --git a/docs/make-api.json b/docs/make-api.json
index 7c11b48..ee90c15 100644
--- a/docs/make-api.json
+++ b/docs/make-api.json
@@ -7,7 +7,7 @@
"include_members": {},
"type_aliases": {
"dag_cbor.decoding": ["DecodeCallback"],
- "dag_cbor.ipld": ["ScalarKind", "Kind", "Path", "Segment"]
+ "dag_cbor.ipld": ["IPLDScalarKind", "IPLDKind", "ObjPath", "ObjPathSegment"]
},
"exclude_members": {},
"include_modules": [],
@@ -18,6 +18,6 @@
],
"member_fullnames": {},
"special_class_members": {
- "dag_cbor.ipld.Path": ["__new__", "__truediv__", "__rtruediv__", "__le__", "__lt__", "__repr__", "__rshift__"]
+ "dag_cbor.ipld.ObjPath": ["__new__", "__truediv__", "__rtruediv__", "__le__", "__lt__", "__repr__", "__rshift__"]
}
}
diff --git a/test/test_03_concat_and_length.py b/test/test_03_concat_and_length.py
index 46b0f8e..2e2448f 100644
--- a/test/test_03_concat_and_length.py
+++ b/test/test_03_concat_and_length.py
@@ -6,7 +6,7 @@
from io import BytesIO
from dag_cbor import encode, decode
-from dag_cbor.ipld import Kind
+from dag_cbor.ipld import IPLDKind
from dag_cbor.random import rand_data
nsamples = 1000
@@ -15,7 +15,7 @@
class BytesReadCounter:
""" Counter for bytes read while decoding. """
_num_bytes_read: int = 0
- def __call__(self, value: Kind, num_bytes_read: int) -> None:
+ def __call__(self, value: IPLDKind, num_bytes_read: int) -> None:
self._num_bytes_read += num_bytes_read
def __int__(self) -> int:
return self._num_bytes_read