Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Publish types for kwargs/classes exposed to the user-side #341

Merged
merged 1 commit into from
Apr 6, 2020

Conversation

nolar
Copy link
Contributor

@nolar nolar commented Apr 2, 2020

What do these changes do?

Publishes all object types which are exposed to the user-side: as handlers' kwargs or as overridable classes.

Description

This was actually promised in #194, but not actually implemented.

With these types exposed, the users can type-annotate the kwargs, making them friendly in the IDEs, or or to type-check their operators. It is more wordy than in the examples/docs, but this is how type annotations generally work:

from typing import Any
import kopf

@kopf.on.create('zalando.org', 'v1', 'ephemeralvolumeclaims')
def create_fn(
        spec: kopf.Spec, name: str, namespace: str, patch: kopf.Patch,
        logger: kopf.ObjectLogger, **_: Any):
    ...

Another group of classes exposed are those supposed to be used in the overridden/inherited classes, such as persistence storage classes: the storage classes were exposed, but the types of their arguments were not. This is now fixed.

There are no changes in the behaviour.

The UserDict class is renamed to Memo to make it more clear what kind of an object it is (not only a dict, but also free-named field container). The kwargs remains the same: memo.

Issues/PRs

Issues: #194 #200

Type of changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • The code addresses only the mentioned problem, and this problem only
  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt

This allows putting the type annotations on the handlers, and writing
better type-checkable operators. This also improves the IDE experience
with field and method hinting of the arguments.
@zincr
Copy link

zincr bot commented Apr 2, 2020

🤖 zincr found 0 problems , 0 warnings

✅ Large Commits
✅ Approvals
✅ Specification
✅ Dependency Licensing

@nolar nolar added the enhancement New feature or request label Apr 2, 2020
@nolar nolar requested a review from mnarodovitch April 3, 2020 08:54
@nolar nolar merged commit 783932f into zalando-incubator:master Apr 6, 2020
@nolar nolar deleted the expose-types branch April 6, 2020 10:40
@nolar nolar added this to the 0.27 milestone May 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants