jgdv.decorators.proto
Classes
A Class Decorator to ensure a class has no abc.abstractmethod's |
|
Decorator to explicitly annotate a class as an implementer of a set of protocols. |
Module Contents
- class jgdv.decorators.proto.CheckProtocols[source]
Bases:
jgdv.decorators._core._DecAnnotate_mA Class Decorator to ensure a class has no abc.abstractmethod’s or unimplemented protocol members
pass additional protocols when making the decorator, eg:
@CheckProtocol(Proto1_p, Proto2_p, AbsClass...) class MyClass: pass
- test_protocol(proto, cls) <Unknown>[source]
Returns a list of methods which are defined in the protocol, and nowhere else in the mro.
ie: they are unimplemented protocol requirements
Can handle type aliases, so long as they actually point to a protocol. | eg: type proto_alias = MyProtocol_p | where issubclass(MyProtocol_p, Protocol)
- _data_key = None
- class jgdv.decorators.proto.Proto(*protos, check=True, mod_mro=False)[source]
Bases:
jgdv.decorators._core.MonotonicDecDecorator to explicitly annotate a class as an implementer of a set of protocols.
Protocols are annotated into cls._jgdv_protos : set[Protocol]:
class ClsName(Supers*, P1, P1..., **kwargs):...
becomes:
@Protocols(P1, P2,...) class ClsName(Supers): ...
Protocol definition remains the usual way:
class Proto1(Protocol): ... class ExtProto(Proto1, Protocol): ...
- _build_annotations_h(target, current) <Unknown>[source]
Given a list of the current annotation list, return its replacement
- _validate_target_h(
- target,
- form,
- args=None,
Abstract class for specialization. Given the original target, throw an error here if it isn’t ‘correct’ in some way
- Parameters:
target (jgdv.decorators._interface.Decorable)
args (jgdv.Maybe[list])
- Return type:
None
- _checker: ClassVar[CheckProtocols]
- needs_args = True