The legacy Node and Link classes in dag/dag.py are not exported from dag/__init__.py, but utils.py references them via node_to_link(). This creates an inconsistency where internal code uses classes that aren't part of the public API.
Problem
In dag/__init__.py:
from .block import Block
from .codec import BlockCodec, BlockDecoder, BlockEncoder, ...
from .ipld_model import CID, IPLDNode, Kind, ...
from .multicodec_codes import ...
# ← Node and Link are NOT exported
But in dag/utils.py:
def node_to_link(node: Any) -> Any:
from .dag import Link, Node # ← Imports from internal module
if not isinstance(node, Node):
raise TypeError("node should be an instance of type Node")
return Link("", node.size, node.multihash)
Users can't use node_to_link() without also importing from the internal dag.dag module.
Proposed Solution
Either:
Option A: Export Node and Link from __init__.py:
from .dag import Node, Link
__all__ = [
# ... existing exports ...
"Node",
"Link",
]
Option B: Deprecate node_to_link() and remove the legacy classes:
import warnings
def node_to_link(node: Any) -> Any:
warnings.warn(
"node_to_link() is deprecated. Use the Block/codec API instead.",
DeprecationWarning,
stacklevel=2,
)
# ...
Related
- Files:
dag/__init__.py, dag/dag.py, dag/utils.py
The legacy
NodeandLinkclasses indag/dag.pyare not exported fromdag/__init__.py, bututils.pyreferences them vianode_to_link(). This creates an inconsistency where internal code uses classes that aren't part of the public API.Problem
In
dag/__init__.py:But in
dag/utils.py:Users can't use
node_to_link()without also importing from the internaldag.dagmodule.Proposed Solution
Either:
Option A: Export
NodeandLinkfrom__init__.py:Option B: Deprecate
node_to_link()and remove the legacy classes:Related
dag/__init__.py,dag/dag.py,dag/utils.py