Skip to content

Type annotations for celery/apps/beat.py#8108

Merged
auvipy merged 20 commits intocelery:mainfrom
max-muoto:beat.py-annotations
Mar 9, 2023
Merged

Type annotations for celery/apps/beat.py#8108
auvipy merged 20 commits intocelery:mainfrom
max-muoto:beat.py-annotations

Conversation

@max-muoto
Copy link
Copy Markdown
Contributor

Note: Before submitting this pull request, please review our contributing
guidelines
.

Description

Type annotations for celery/apps/beat.py as a part of #7394.

max-muoto and others added 5 commits March 5, 2023 12:45
* Annotate text

* fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix

* fix

* Add to pyproject

* Fix

* remove comment

* Small fix

* remove comment

* remoev unused arg

* Fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix

* fix

* build fix

* type fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* pytest==7.2.2 (celery#8106)

* Fix

* Fix

* Type checking fix

* Update celery/utils/text.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 5, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.01 ⚠️

Comparison is base (32a83e2) 87.02% compared to head (5db7eea) 87.01%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8108      +/-   ##
==========================================
- Coverage   87.02%   87.01%   -0.01%     
==========================================
  Files         148      148              
  Lines       18445    18449       +4     
  Branches     2515     2515              
==========================================
+ Hits        16051    16054       +3     
- Misses       2116     2118       +2     
+ Partials      278      277       -1     
Flag Coverage Δ
unittests 86.99% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
celery/apps/beat.py 91.02% <100.00%> (+0.48%) ⬆️
celery/schedules.py 97.53% <100.00%> (ø)
celery/backends/asynchronous.py 64.93% <0.00%> (-0.44%) ⬇️
celery/app/base.py 96.72% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

)

def install_sync_handler(self, service):
def install_sync_handler(self, service: Service) -> None:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-commit was replacing quoted type hints. Is this intended? I think it would be useful to allow them, so that I could conditionally import types with if TYPE_CHECKING.

@max-muoto max-muoto marked this pull request as ready for review March 5, 2023 19:05
@Nusnus
Copy link
Copy Markdown
Member

Nusnus commented Mar 5, 2023

The CI was stuck - on it

@max-muoto
Copy link
Copy Markdown
Contributor Author

The CI was stuck - on it

Hmm, not able to replicate locally. Do you have any debugging advice? Never really seen a CI just get stuck.

@Nusnus
Copy link
Copy Markdown
Member

Nusnus commented Mar 5, 2023

The CI was stuck - on it

Hmm, not able to replicate locally. Do you have any debugging advice? Never really seen a CI just get stuck.

Tbh "stuck" isn't accurate, it was pending/waiting due to a time limit if I'm not mistaken.

I've stopped the run and will re-run soon. It should allow everything to run smoothly.

@max-muoto
Copy link
Copy Markdown
Contributor Author

max-muoto commented Mar 5, 2023 via email

@Nusnus
Copy link
Copy Markdown
Member

Nusnus commented Mar 5, 2023

Thank You friend!
I personally like annotations so it's a great PR IMHO.

And don't worry, I got my eyes on the CI. If something happens I'll comment/fix etc.

def app(self) -> Celery:
if self._app:
return self._app
raise ValueError("Beat must provided a Celery app.")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added lines #L83 - L84 were not covered by tests

Can you add a unit test for this please?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do for both!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed a type hint (scheduler/scheduler_cls), and added a test that covers both.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to have some trouble running unit tests locally, pytest must be caching (or something else, not sure) as the new field on the Beat class isn't even picked up when inspecting with pdb. Do you have any ideas here?


@app.setter
def app(self, app: Celery) -> None:
self._app = app
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added line #L88 was not covered by tests

Can you add a unit test for this please?

@Nusnus Nusnus added this to the 5.3 milestone Mar 5, 2023
@Nusnus
Copy link
Copy Markdown
Member

Nusnus commented Mar 5, 2023

@Nusnus Nusnus self-requested a review March 5, 2023 23:00
@max-muoto
Copy link
Copy Markdown
Contributor Author

max-muoto commented Mar 8, 2023

@Nusnus Modified it a way that doesn't require a setter/getter so removed the test, if you want to take another look.

It turns out there was no need to explicitly set the app field in the class to None, since it gets overridden anyway when grabbing it from the app. If it isn't set, and no app was provided for the init, then it doesn't make a difference since it would have run into an attribute error trying to call a method on app anyway.

Copy link
Copy Markdown
Member

@Nusnus Nusnus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@auvipy LGTM

@auvipy auvipy merged commit 93bccdc into celery:main Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants