Skip to content

Legacy Node/Link classes not exported from __init__.py #30

Description

@sumanjeet0012

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions