Skip to content

Commit

Permalink
Add type hints (#189)
Browse files Browse the repository at this point in the history
The type hints are only checked for Python 3.7+

* New step in CI: mypy.

Co-authored-by: Carlo Bertini <[email protected]>
  • Loading branch information
Mulugruntz and WaYdotNET authored Feb 14, 2023
1 parent 56b8bed commit fb09e13
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 37 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ jobs:
pip install "celery${{ matrix.celery }}"
pip install pytest-github-actions-annotate-failures
- name: Check with mypy
if: ${{ !startsWith(matrix.python-version, 'pypy') && matrix.python-version >= '3.7' }}
run: mypy

- name: Lint with flake8
run: |
pip install flake8
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/resolve_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ def parse_args() -> Namespace:
)
parser_matrix.add_argument("-n", "--package-name", type=str, help="Package name")
parser_matrix.add_argument("-s", "--specifiers", type=str, help="Specifiers")
parser_matrix.add_argument("--invert", action="store_true", default=False, help="Invert matrix (only show the skipped ones)")
parser_matrix.add_argument(
"--invert",
action="store_true",
default=False,
help="Invert matrix (only show the skipped ones)",
)

return parser.parse_args()

Expand Down
66 changes: 34 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# celery-pubsub 1.0.1
# celery-pubsub 1.0.2


[![image](https://travis-ci.org/Mulugruntz/celery-pubsub.svg?branch=master)](https://travis-ci.org/Mulugruntz/celery-pubsub)
[![Build and Test](https://github.com/Mulugruntz/celery-pubsub/actions/workflows/build.yml/badge.svg)](https://github.com/Mulugruntz/celery-pubsub/actions/workflows/build.yml)
[![Code Climate](https://codeclimate.com/github/Mulugruntz/celery-pubsub/badges/gpa.svg)](https://codeclimate.com/github/Mulugruntz/celery-pubsub)
[![Test Coverage](https://codeclimate.com/github/Mulugruntz/celery-pubsub/badges/coverage.svg)](https://codeclimate.com/github/Mulugruntz/celery-pubsub/coverage)
[![Issue Count](https://codeclimate.com/github/Mulugruntz/celery-pubsub/badges/issue_count.svg)](https://codeclimate.com/github/Mulugruntz/celery-pubsub)
Expand Down Expand Up @@ -102,6 +102,8 @@ celery_pubsub.publish('some.very.good.test', 42) # task 3 only

## Changelog

* 1.0.2
* Add stubs file for type hinting.
* 1.0.1
* Changed `README.rst` to `README.md`.
* Added better badges to show the supported status for each Celery & Python version.
Expand Down Expand Up @@ -197,42 +199,42 @@ celery_pubsub.publish('some.very.good.test', 42) # task 3 only
[badge-m_linux_pypy3.6_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/m_linux_pypy-3.6_celery5/shields

[//]: # (Status in tagged version)
[badge-t_linux_2.7_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_2.7_celery3/shields
[badge-t_linux_2.7_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_2.7_celery4/shields
[badge-t_linux_2.7_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_2.7_celery5/shields
[badge-t_linux_2.7_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_2.7_celery3/shields
[badge-t_linux_2.7_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_2.7_celery4/shields
[badge-t_linux_2.7_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_2.7_celery5/shields

[badge-t_linux_3.4_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.4_celery3/shields
[badge-t_linux_3.4_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.4_celery4/shields
[badge-t_linux_3.4_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.4_celery5/shields
[badge-t_linux_3.4_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.4_celery3/shields
[badge-t_linux_3.4_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.4_celery4/shields
[badge-t_linux_3.4_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.4_celery5/shields

[badge-t_linux_3.5_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.5_celery3/shields
[badge-t_linux_3.5_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.5_celery4/shields
[badge-t_linux_3.5_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.5_celery5/shields
[badge-t_linux_3.5_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.5_celery3/shields
[badge-t_linux_3.5_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.5_celery4/shields
[badge-t_linux_3.5_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.5_celery5/shields

[badge-t_linux_3.6_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.6_celery3/shields
[badge-t_linux_3.6_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.6_celery4/shields
[badge-t_linux_3.6_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.6_celery5/shields
[badge-t_linux_3.6_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.6_celery3/shields
[badge-t_linux_3.6_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.6_celery4/shields
[badge-t_linux_3.6_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.6_celery5/shields

[badge-t_linux_3.7_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.7_celery3/shields
[badge-t_linux_3.7_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.7_celery4/shields
[badge-t_linux_3.7_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.7_celery5/shields
[badge-t_linux_3.7_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.7_celery3/shields
[badge-t_linux_3.7_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.7_celery4/shields
[badge-t_linux_3.7_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.7_celery5/shields

[badge-t_linux_3.8_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.8_celery3/shields
[badge-t_linux_3.8_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.8_celery4/shields
[badge-t_linux_3.8_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.8_celery5/shields
[badge-t_linux_3.8_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.8_celery3/shields
[badge-t_linux_3.8_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.8_celery4/shields
[badge-t_linux_3.8_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.8_celery5/shields

[badge-t_linux_3.9_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.9_celery3/shields
[badge-t_linux_3.9_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.9_celery4/shields
[badge-t_linux_3.9_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.9_celery5/shields
[badge-t_linux_3.9_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.9_celery3/shields
[badge-t_linux_3.9_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.9_celery4/shields
[badge-t_linux_3.9_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.9_celery5/shields

[badge-t_linux_3.10_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.10_celery3/shields
[badge-t_linux_3.10_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.10_celery4/shields
[badge-t_linux_3.10_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_3.10_celery5/shields
[badge-t_linux_3.10_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.10_celery3/shields
[badge-t_linux_3.10_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.10_celery4/shields
[badge-t_linux_3.10_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_3.10_celery5/shields

[badge-t_linux_pypy2.7_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_pypy-2.7_celery3/shields
[badge-t_linux_pypy2.7_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_pypy-2.7_celery4/shields
[badge-t_linux_pypy2.7_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_pypy-2.7_celery5/shields
[badge-t_linux_pypy2.7_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_pypy-2.7_celery3/shields
[badge-t_linux_pypy2.7_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_pypy-2.7_celery4/shields
[badge-t_linux_pypy2.7_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_pypy-2.7_celery5/shields

[badge-t_linux_pypy3.6_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_pypy-3.6_celery3/shields
[badge-t_linux_pypy3.6_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_pypy-3.6_celery4/shields
[badge-t_linux_pypy3.6_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.1_linux_pypy-3.6_celery5/shields
[badge-t_linux_pypy3.6_celery3]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_pypy-3.6_celery3/shields
[badge-t_linux_pypy3.6_celery4]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_pypy-3.6_celery4/shields
[badge-t_linux_pypy3.6_celery5]: https://byob.yarr.is/Mulugruntz/celery-pubsub/1.0.2_linux_pypy-3.6_celery5/shields
4 changes: 4 additions & 0 deletions celery_pubsub/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .pubsub import publish as publish
from .pubsub import publish_now as publish_now
from .pubsub import subscribe as subscribe
from .pubsub import unsubscribe as unsubscribe
21 changes: 21 additions & 0 deletions celery_pubsub/pubsub.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import re
from typing import Any

from celery import Task, group
from celery.result import AsyncResult

class PubSubManager:
subscribed: set[tuple[str, re.Pattern[str], Task[Any, Any]]]
jobs: dict[str, group]
def publish(self, topic: str, *args: Any, **kwargs: Any) -> AsyncResult[Any]: ...
def publish_now(
self, topic: str, *args: Any, **kwargs: Any
) -> AsyncResult[Any]: ...
def subscribe(self, topic: str, task: Task[Any, Any]) -> None: ...
def unsubscribe(self, topic: str, task: Task[Any, Any]) -> None: ...
def get_jobs(self, topic: str) -> group: ...

def publish(topic: str, *args: Any, **kwargs: Any) -> AsyncResult[Any]: ...
def publish_now(topic: str, *args: Any, **kwargs: Any) -> AsyncResult[Any]: ...
def subscribe(topic: str, task: Task[Any, Any]) -> None: ...
def unsubscribe(topic: str, task: Task[Any, Any]) -> None: ...
4 changes: 4 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[mypy]
strict = True
# Only check files in the `celery_pubsub` package
files = celery_pubsub
6 changes: 5 additions & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
pytest
coverage==5.5
coverage==5.5

# Only for Python 3.7+ (also exclude pypy).
celery-types==0.14.0; python_version >= '3.7' and implementation_name != 'pypy'
mypy==1.0.0; python_version >= '3.7' and implementation_name != 'pypy'
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def tests_require():
setuptools.setup(
name="celery-pubsub",
packages=["celery_pubsub"],
version="1.0.1",
version="1.0.2",
description="A Publish and Subscribe library for Celery",
long_description=long_description(),
long_description_content_type="text/markdown",
author="Samuel GIFFARD",
author_email="[email protected]",
license="MIT",
url="https://github.com/Mulugruntz/celery-pubsub",
download_url="https://github.com/Mulugruntz/celery-pubsub/tarball/1.0.1",
download_url="https://github.com/Mulugruntz/celery-pubsub/tarball/1.0.2",
keywords=["celery", "publish", "subscribe", "pubsub"],
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
def celery_worker():
pass


else: # pragma: no cover
task = celery.shared_task

Expand Down

0 comments on commit fb09e13

Please sign in to comment.