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

docs: kick start the process of adding type definitions #684

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

a-ungurianu
Copy link
Member

Beginnings of #647

Why is this needed?

Python type annotations are a great way of documenting the APIs, as well as improving the developer experience when using this library.

I find the actual type checking to be an added benefit than a necessity.

Proposed Changes

  • type the election, lock, lease, counter, barrier and party recipes
  • configure and add mypy to CI

Does this PR introduce any breaking change?

  • I hope not, but there are some real code changes along side the annotations

kazoo/client.py Outdated Show resolved Hide resolved
kazoo/recipe/barrier.py Outdated Show resolved Hide resolved
kazoo/recipe/barrier.py Outdated Show resolved Hide resolved
kazoo/recipe/counter.py Outdated Show resolved Hide resolved
kazoo/recipe/counter.py Outdated Show resolved Hide resolved
kazoo/recipe/lease.py Outdated Show resolved Hide resolved
kazoo/recipe/lease.py Show resolved Hide resolved
kazoo/recipe/lease.py Outdated Show resolved Hide resolved
kazoo/recipe/lock.py Outdated Show resolved Hide resolved
kazoo/recipe/lock.py Outdated Show resolved Hide resolved
kazoo/recipe/lock.py Outdated Show resolved Hide resolved
kazoo/recipe/lock.py Outdated Show resolved Hide resolved
kazoo/recipe/lock.py Outdated Show resolved Hide resolved
kazoo/recipe/lock.py Outdated Show resolved Hide resolved
kazoo/recipe/party.py Show resolved Hide resolved
kazoo/recipe/party.py Outdated Show resolved Hide resolved
kazoo/recipe/party.py Outdated Show resolved Hide resolved
kazoo/recipe/party.py Outdated Show resolved Hide resolved
kazoo/recipe/party.py Outdated Show resolved Hide resolved
@a-ungurianu a-ungurianu force-pushed the refactor/type_some_recipes branch 2 times, most recently from a482057 to bcc5602 Compare November 15, 2022 23:32
@ceache
Copy link
Contributor

ceache commented Nov 16, 2022

Hi @a-ungurianu,

Awesome that you started that work!!

Full disclosure, I haven't reviewed all the changes but one thing I wanted to mention is trying to minimize imports at runtime. 

In most of my projects, i am able to only import TYPE_CHECKING and occasionally cast like so:

from typing import TYPE_CHECKING

# ... other imports

if TYPE_CHECKING:  # pragma: nocover
    from typing import...
    from typing_extensions import...
    T = TypeVar(...)

I have seen numerous other projects doing that as well.

What do you think?

kazoo/recipe/lock.py Outdated Show resolved Hide resolved
kazoo/recipe/lock.py Outdated Show resolved Hide resolved
@a-ungurianu
Copy link
Member Author

I think I agree. I've just been adding any new modules inside the TYPE_CHECKING check, but adding all imports used for typing and repeating module imports makes sense.

@a-ungurianu a-ungurianu force-pushed the refactor/type_some_recipes branch 8 times, most recently from 16f1829 to 755c416 Compare November 18, 2022 20:05
@codecov-commenter
Copy link

codecov-commenter commented Nov 18, 2022

Codecov Report

Attention: Patch coverage is 82.60870% with 28 lines in your changes are missing coverage. Please review.

Project coverage is 96.19%. Comparing base (2fb93a8) to head (07bbc80).
Report is 3 commits behind head on master.

Files Patch % Lines
kazoo/client.py 82.50% 7 Missing ⚠️
kazoo/recipe/barrier.py 81.81% 4 Missing ⚠️
kazoo/recipe/election.py 63.63% 4 Missing ⚠️
kazoo/retry.py 50.00% 4 Missing ⚠️
kazoo/recipe/counter.py 86.36% 3 Missing ⚠️
kazoo/recipe/party.py 90.62% 3 Missing ⚠️
kazoo/recipe/lease.py 89.47% 2 Missing ⚠️
kazoo/recipe/lock.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #684      +/-   ##
==========================================
- Coverage   96.81%   96.19%   -0.62%     
==========================================
  Files          27       27              
  Lines        3549     3628      +79     
==========================================
+ Hits         3436     3490      +54     
- Misses        113      138      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@a-ungurianu a-ungurianu marked this pull request as ready for review January 28, 2023 16:42
kazoo/client.py Outdated Show resolved Hide resolved
kazoo/client.py Outdated Show resolved Hide resolved
kazoo/client.py Outdated Show resolved Hide resolved
kazoo/client.py Outdated Show resolved Hide resolved
kazoo/client.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
kazoo/client.py Outdated Show resolved Hide resolved
kazoo/client.py Outdated Show resolved Hide resolved
kazoo/client.py Outdated Show resolved Hide resolved
kazoo/client.py Outdated Show resolved Hide resolved
kazoo/client.py Outdated Show resolved Hide resolved
kazoo/client.py Outdated Show resolved Hide resolved
kazoo/client.py Outdated Show resolved Hide resolved
kazoo/client.py Outdated Show resolved Hide resolved
kazoo/client.py Outdated Show resolved Hide resolved
kazoo/client.py Outdated Show resolved Hide resolved
@a-ungurianu
Copy link
Member Author

This is ready for a proper review now.

The history log in the PR is a bit of a mess for this due to me fighting with Hound and with making sure the stuff used from typing is available from 3.7 upwards

@a-ungurianu a-ungurianu changed the title Kick start the process of adding type definitions docs: kick start the process of adding type definitions Feb 13, 2023
@a-ungurianu a-ungurianu requested review from bringhurst and ceache and removed request for bringhurst February 26, 2023 01:03
@takeda
Copy link

takeda commented Feb 8, 2024

@a-ungurianu any chance this would get merged?

@a-ungurianu
Copy link
Member Author

I'm considering declaring bankruptcy on this PR and re-openning so that it looks a bit more approachable for review.

Also, if there's anything in the structure that makes it hard to review, lemme know and I can amend

@StephenSorriaux
Copy link
Member

StephenSorriaux commented May 2, 2024

Would it be possible to exclude the if TYPE_CHECKING: lines from the test coverage? So that codecov can give us a "true" coverage. (see https://coverage.readthedocs.io/en/latest/excluding.html#advanced-exclusion)
Probably the ... and/or @overload too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants