Coding 2025-08-21
All right, let's see about that descriptor concept. It's going to look something like:
@attrs.frozen
class Coerce[T]:
ctor: Callable[[type[T]], T]
def __get__(
self, instance: T | None, owner: type[T]
) -> Callable[, Constraints[Bundle[T]]]:
def coerce(type_bundle: Bundle[Any]) -> Constraints[Bundle[T]]:
typ = type_bundle.data
if isinstance(typ, owner):
return Bundle(typ, type_bundle.metadata)
yield from ()
return type_bundle.extend(
lambda n: self.ctor(owner),
CoercionFailure(),
)
return coerce
Okay, let's ponder this. I'm feeling okay about this, but I'm assuming that I'd need to tweak this some to make it actually work with Mypy.
Anyway, I'm going to sleep on this, and get to bed soon.
Good night.