plugin.core: Less introspective DIRECTIVE setting.

Python 3.6 does not implement __class_getitem__, and because of that
it's not possible to introspect when things like Hook[Transaction]
are called. Sidestep the issue with a more explicit assignment.
This commit is contained in:
Brett Smith 2020-04-06 15:18:54 -04:00
parent 6f3e5eb905
commit e1c507c025

View file

@ -69,12 +69,10 @@ class Hook(Generic[Entry], metaclass=abc.ABCMeta):
@abc.abstractmethod
def run(self, entry: Entry) -> errormod.Iter: ...
def __init_subclass__(cls) -> None:
# cls.__orig_bases__ comes from the ABCMeta metaclass
cls.DIRECTIVE = cls.__orig_bases__[0].__args__[0] # type:ignore[attr-defined]
class TransactionHook(Hook[Transaction]):
DIRECTIVE = Transaction
TransactionHook = Hook[Transaction]
### HELPER CLASSES