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

Turn on typechecking in our GitHub CI #14

Merged
merged 7 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ lint:
$(PYTHON) -m flake8 --config=$(CURDIR)/tests/.flake8 tests
$(PYTHON) -m flake8 --config=$(CURDIR)/tests/.flake8 examples
$(PYTHON) -m isort --check-only --settings-path=$(CURDIR)/.isort.cfg src tests examples setup.py
MYPYPATH=src $(PYTHON) -m mypy --strict examples
MYPYPATH=src $(PYTHON) -m mypy --strict examples src
clang-format --Werror --dry-run src/cpp/*

# https://www.npmjs.com/package/markdownlint-cli
Expand Down
1 change: 1 addition & 0 deletions news/6.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enabled source code typechecking in the GitHub CI
21 changes: 11 additions & 10 deletions src/blazingmq/_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@
from typing import Callable
from typing import Dict
from typing import Iterable
from typing import Mapping
from typing import Optional
from typing import TYPE_CHECKING
from typing import Tuple
from typing import Type
from typing import Union
import weakref

from ._enums import AckStatus
from ._enums import PropertyType
from ._messages import Ack
from ._messages import AckStatus
from ._messages import Message
from ._messages import MessageHandle
from ._messages import create_ack
from ._messages import create_message
from ._messages import create_message_handle
Expand Down Expand Up @@ -90,33 +92,32 @@ def on_session_event(
event_cls = failure_class_by_success_class[event_cls]

assert queue_uri
event = event_cls(queue_uri, msg)
event: SessionEvent = event_cls(queue_uri, msg)
else:
event = event_cls(msg)

# Invoke user callback
user_callback(event)


PropertiesAndTypesDictsType = Tuple[
Dict[str, Union[int, bytes]], Dict[str, PropertyType]
]
PropertiesAndTypesDictsType = Tuple[Dict[str, Union[int, bytes]], Dict[str, int]]


def on_message(
user_callback: Callable[[Message], None],
user_callback: Callable[[Message, MessageHandle], None],
ext_session_wr: weakref.ref[_ext.Session],
property_type_to_py: Dict[int, PropertyType],
property_type_to_py: Mapping[int, PropertyType],
messages: Iterable[Tuple[bytes, bytes, bytes, PropertiesAndTypesDictsType]],
) -> None:
ext_session = ext_session_wr()
assert ext_session is not None, "ext.Session has been deleted"
for data, guid, queue_uri, properties_tuple in messages:
properties, property_types = properties_tuple
for k, v in property_types.items():
property_types[k] = property_type_to_py[v]
property_types_py = {
k: property_type_to_py[v] for k, v in property_types.items()
}
message = create_message(
data, guid, queue_uri.decode(), properties, property_types
data, guid, queue_uri.decode(), properties, property_types_py
)
message_handle = create_message_handle(message, ext_session)
user_callback(message, message_handle)
Expand Down
1 change: 1 addition & 0 deletions src/blazingmq/_script_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
def get_script_name() -> bytes:
if getattr(sys.modules.get("__main__"), "__file__", ""):
name = sys.modules["__main__"].__file__
assert name is not None # help the typechecker
return os.fsencode(name)
return b"py:UNKNOWN"
6 changes: 3 additions & 3 deletions src/blazingmq/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Dict
from typing import Mapping
from typing import Union

from ._enums import PropertyType

PropertyValueType = Union[int, bytes, str]

PropertyValueDict = Dict[str, PropertyValueType]
PropertyValueDict = Mapping[str, PropertyValueType]

PropertyTypeDict = Dict[str, PropertyType]
PropertyTypeDict = Mapping[str, PropertyType]
Loading