Accept arbitrary types for memos & results, clarify other kwarg types #747
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Memos are usually of type
kopf.Memo
but can be configured to any custom type (in embedded operators mostly). As such, the framework must not rely on any behaviour of memo instances, so it usesobject
as the type which has no methods or properties or fields.However, for the user-facing signatures of handler callbacks, it is declared as
Any
for the same purpose: to accept any specialised custom type. Users are encouraged to put their own classes as annotations of thememo
kwarg;kopf.Memo
works as well.The original declaration of handler callbacks with
memo: AnyMemo
was problematic as it was forcing the operator developers to acceptmemo
exactly as this type only:Union[kopf.Memo, object]
, not justkopf.Memo
alone — which was against the intended usage scenario with arbitrary custom types or the default type.For even stricter control, to not mess with any other value by accident (as
object
would accept anything), it is redeclared as a new type "AnyMemo". For the user-facing embedded operator functions, it is defined as literallyobject
to prevent exposing the declared new typeAnyMemo
. The type-casting of pureobject
to redeclaredAnyMemo=object
is done at the earliest possible point internally, hidden from the users.Similarly, fixes the differences of the
logger
kwarg (now, there iskopf.Logger
type), and of the handler results (were expected as never-exportedOptional[Result]
, will be expected asOptional[object]
and type-casted where needed).fixes #746