Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve kwargs typing in callbacks protocols #720

Merged
merged 4 commits into from
Mar 27, 2021
Merged

Improve kwargs typing in callbacks protocols #720

merged 4 commits into from
Mar 27, 2021

Conversation

nolar
Copy link
Owner

@nolar nolar commented Mar 27, 2021

In #704, callbacks were properly defined, but this required MyPy extensions (to be released in Python & typing_extensions on Python 3.10 release, presumably Oct'2021). The existence of these extensions required a conditional to avoid installing them at runtime (where they are not needed). Thus, in turn, required quoting (ForwardRef'ing) all references to callbacks.

As a result, this broke IDE navigation, as PyCharm does not understand "quoted" types.

To fix that, a little improvement is added: for runtime, define the same callback protocols, but with no arguments specified — make them just callables. This allows us to unquote the callback types and to use them both at runtime and type-checking time naturally.


In addition, clarify the types of some kwargs and export their same-named types from the root package. Specifically, the labels/annotations are read-only mappings (not necessary dicts), stopped can be sync or async, and body essences (old & new mostly) are not necessary mutable.

In a recent commit, callbacks were properly defined, but this required MyPy extensions (to be released in Python & typing_extensions on Python 3.10 release, presumably Oct'2021). The existence of these extensions required a conditional to avoid installing them at runtime (where they are not needed). Thus, in turn, required quoting (ForwardRef'ing) all references to callbacks.

As a result, this broke IDE navigation, as PyCharm does not understand "quoted" types.

To fix that, a little improvement is added: for runtime, define the same callback protocols, but with no arguments specified — make them just callables. This allows us to unquote the callback types and to use them both at runtime and type-checking time naturally.

Signed-off-by: Sergey Vasilyev <[email protected]>
@nolar nolar added the enhancement New feature or request label Mar 27, 2021
Since annotations become readonly even in body essences, this requires stricter typing in storages.

Signed-off-by: Sergey Vasilyev <[email protected]>
@nolar nolar merged commit 0ad6551 into main Mar 27, 2021
@nolar nolar deleted the protocols branch March 27, 2021 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant