Skip to content

Commit

Permalink
typing: improved mypy support (Bogdanp#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
staticdev authored Mar 18, 2022
1 parent 21dfc90 commit 31053af
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ of those changes to CLEARTYPE SRL.
| [@ethervoid](https://github.com/ethervoid) | Mario de Frutos |
| [@pcrockett](https://github.com/pcrockett) | Phil Crockett |
| [@nathanielobrown](https://github.com/nathanielobrown)| Nathaniel Brown |
| [@staticdev](https://github.com/staticdev) | Thiago |
| [@kurtmckee](https://github.com/kurtmckee) | Kurt McKee |
1 change: 0 additions & 1 deletion docs/source/sitemap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import xml.etree.ElementTree as ET

from datetime import datetime


Expand Down
3 changes: 3 additions & 0 deletions dramatiq/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from typing import cast

from .errors import ActorNotFound
from .logging import get_logger
from .middleware import MiddlewareError, default_middleware
Expand All @@ -41,6 +43,7 @@ def get_broker() -> "Broker":
connection_attempts=5,
blocked_connection_timeout=30,
))
global_broker = cast("Broker", global_broker)
return global_broker


Expand Down
2 changes: 1 addition & 1 deletion dramatiq/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def make_argument_parser():
if hasattr(signal, "SIGHUP"):
HANDLED_SIGNALS.add(signal.SIGHUP)
if hasattr(signal, "SIGBREAK"):
HANDLED_SIGNALS.add(signal.SIGBREAK)
HANDLED_SIGNALS.add(signal.SIGBREAK) # type: ignore


def try_block_signals():
Expand Down
2 changes: 1 addition & 1 deletion dramatiq/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def decode(self, data: bytes) -> MessageData:

try:
return json.loads(data_str)
except json.decoder.DecodeError as e:
except json.decoder.JSONDecodeError as e:
raise DecodeError("failed to decode message %r" % (data_str,), data_str, e) from None


Expand Down
Empty file added dramatiq/py.typed
Empty file.
3 changes: 2 additions & 1 deletion dramatiq/results/backends/stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import time
from typing import Dict, Optional, Tuple

from ..backend import Missing, ResultBackend

Expand All @@ -29,7 +30,7 @@ class StubBackend(ResultBackend):
result data. Defaults to :class:`.JSONEncoder`.
"""

results = {}
results: Dict[str, Tuple[Optional[str], Optional[float]]] = {}

def _get(self, message_key):
data, expiration = self.results.get(message_key, (None, None))
Expand Down
29 changes: 29 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[mypy]
pretty = True
show_column_numbers = True
show_error_codes = True
show_error_context = True

[mypy-gevent]
ignore_missing_imports = True

[mypy-greenlet]
ignore_missing_imports = True

[mypy-pika.*]
ignore_missing_imports = True

[mypy-prometheus_client]
ignore_missing_imports = True

[mypy-pylibmc]
ignore_missing_imports = True

[mypy-redis]
ignore_missing_imports = True

[mypy-watchdog.*]
ignore_missing_imports = True

[mypy-watchdog_gevent]
ignore_missing_imports = True
1 change: 1 addition & 0 deletions tests/middleware/test_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dramatiq
from dramatiq.brokers.stub import StubBroker
from dramatiq.middleware import shutdown, threading

from ..common import skip_with_gevent, skip_without_gevent

not_supported = threading.current_platform not in threading.supported_platforms
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import dramatiq
from dramatiq.brokers.redis import RedisBroker
from dramatiq.middleware import Middleware
from dramatiq.common import current_millis
from dramatiq.middleware import Middleware

from .common import skip_on_windows

Expand Down

0 comments on commit 31053af

Please sign in to comment.