I currently have a class decorator which will bootstrap a defined class with a set of attributes & methods, i.e.:
from typing import Callable, Generic, TypeVar T = TypeVar("T") class Bootstrapped(Generic[T]): myattr: str mymethod: Callable[[T], str] def bootstrap(cls: T) -> Bootstrapped[T]: # impl here pass
AFAICT, the closest thing I can do is a
Union[T, Bootstrapped[T]]. This at least stops type-checkers from complaining, but it’s not really correct, as we’re notating with that annotation that the type is either
Bootstrapped[T]. What I want is a notation which can say the type is both
Anyone have thoughts on how this may be accomplished without writing a custom plugin for mypy, etc?