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
Go provides
var Undef = Cid{}as a sentinel for nil/undefined CIDs. Python has no equivalent, forcing users to useNonewhich loses type information.Problem
Go:
Python:
Proposed Solution
Add an
Undefsentinel:Export from
__init__.py.Related
cid.govar Undef = Cid{}