Skip to content

Commit 23afa20

Browse files
committed
Add some typing and py.typed
This also discovered the missing definition of an abstract base broadcast_status from the CommonTransport class.
1 parent 8ff34d8 commit 23afa20

6 files changed

Lines changed: 15 additions & 6 deletions

File tree

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ recursive-exclude * *.py[co]
1010

1111
recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif
1212

13+
include src/workflows/py.typed

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ package_dir =
3535
=src
3636
python_requires = >=3.7
3737
zip_safe = False
38+
include_package_data = True
3839

3940
[options.extras_require]
4041
prometheus = prometheus-client

src/workflows/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
__version__ = "2.24.1"
44

55

6-
def version():
6+
def version() -> str:
77
"""Returns the version number of the installed workflows package."""
88
return __version__
99

src/workflows/py.typed

Whitespace-only changes.

src/workflows/transport/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@
22

33
import argparse
44
import optparse
5-
from typing import Union
5+
from typing import TYPE_CHECKING, Type
66

77
import pkg_resources
88

9+
if TYPE_CHECKING:
10+
from .common_transport import CommonTransport
11+
912
default_transport = "PikaTransport"
1013

1114

12-
def lookup(transport):
15+
def lookup(transport: str) -> Type[CommonTransport]:
1316
"""Get a transport layer class based on its name."""
1417
return get_known_transports().get(
1518
transport, get_known_transports()[default_transport]
1619
)
1720

1821

1922
def add_command_line_options(
20-
parser: Union[argparse.ArgumentParser, optparse.OptionParser],
23+
parser: argparse.ArgumentParser | optparse.OptionParser,
2124
transport_argument: bool = False,
2225
) -> None:
2326
"""Add command line options for all available transport layer classes."""
@@ -52,7 +55,7 @@ def add_command_line_options(
5255
transport().add_command_line_options(parser)
5356

5457

55-
def get_known_transports():
58+
def get_known_transports() -> dict[str, Type[CommonTransport]]:
5659
"""Return a dictionary of all known transport mechanisms."""
5760
if not hasattr(get_known_transports, "cache"):
5861
setattr(
@@ -63,4 +66,4 @@ def get_known_transports():
6366
for e in pkg_resources.iter_entry_points("workflows.transport")
6467
},
6568
)
66-
return get_known_transports.cache.copy()
69+
return get_known_transports.cache.copy() # type: ignore

src/workflows/transport/common_transport.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ def raw_broadcast(self, destination, message, **kwargs):
315315

316316
self._broadcast(destination, message, **kwargs)
317317

318+
def broadcast_status(self, status: dict) -> None:
319+
"""Broadcast transient status information to all listeners"""
320+
raise NotImplementedError
321+
318322
@middleware.wrap
319323
def ack(self, message, subscription_id: Optional[int] = None, **kwargs):
320324
"""Acknowledge receipt of a message. This only makes sense when the

0 commit comments

Comments
 (0)