Skip to content

No Undef sentinel for representing nil/undefined CIDs #68

Description

@sumanjeet0012

Go provides var Undef = Cid{} as a sentinel for nil/undefined CIDs. Python has no equivalent, forcing users to use None which loses type information.

Problem

Go:

var Undef = Cid{}

func processCID(c Cid) {
    if !c.Defined() {
        // Handle undefined CID
    }
}

Python:

def process_cid(cid):
    if cid is None:
        # Handle undefined CID — but cid could be CIDv0 or CIDv1
        pass

Proposed Solution

Add an Undef sentinel:

class _UndefCID:
    """Sentinel for undefined/nil CID."""
    def defined(self) -> bool:
        return False
    def __bool__(self) -> bool:
        return False
    def __repr__(self) -> str:
        return "CID.Undef"
    def __eq__(self, other):
        return isinstance(other, _UndefCID)

Undef = _UndefCID()

Export from __init__.py.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions