The cell type filled neither the richcompare nor the repr slot, so
object's address-based defaults showed through: cell(1) == cell(1) was
False, ordering raised TypeError, and repr rendered
<cell object at 0x...> rather than <cell at 0x...: int object at 0x...>.
Compare cells by contents, with empty cells ordering before everything
else, and render CPython's repr for both the filled and empty cases.
The comparison fills the richcompare slot directly rather than going
through Comparable, whose cmp() can only answer with a bool. CPython
returns whatever PyObject_RichCompare produced, so a contained __eq__
that yields a non-bool must pass through untouched; coercing it would
also call __bool__ and surface exceptions CPython never raises. The
empty-cell branch still answers with a bool, so both arms are needed and
the slot returns Either.
The repr truncates the contained type name the way "%.80s" does: at most
80 bytes, dropping a character the cut would leave incomplete.
Mark the type unhashable. Content-based equality combined with the
inherited identity hash would break the hash/eq contract, and hashing the
contents is not possible either because cell_contents is writable.
CPython gets this implicitly, because defining tp_richcompare suppresses
tp_hash inheritance.
Reference: CPython Objects/cellobject.c, cell_richcompare and cell_repr.
Assisted-by: Claude Code:claude-opus-5
* Fix function attribute tests: __defaults__ del, __code__ free vars check, bound method dir()
- Support `del func.__defaults__` and `del func.__kwdefaults__` by changing
setter signatures to `PySetterValue<Option<...>>` so Delete is treated as
setting the value to None (matching CPython behaviour)
- Validate free-variable count when assigning to `func.__code__`: raise
ValueError when the new code object's freevars count doesn't match the
existing closure size
- Add `__dir__` to `PyBoundMethod` that delegates to the underlying
function's dir(), so attributes set on the function show up in
`dir(bound_method)`
- Remove `@unittest.expectedFailure` from the four tests that now pass:
test_blank_func_defaults, test_func_default_args, test___code__,
test_dir_includes_correct_attrs
* Remove expectedFailure markers for now-passing tests