Skip to content

Commit

Permalink
Merge b05538b into 7327a05
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-k committed Aug 16, 2023
2 parents 7327a05 + b05538b commit 80e5ec6
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.6
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade "build>=0.3.1" "twine>=3.4.1"
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ jobs:
fail-fast: false
matrix:
python-version:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "3.10"
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

unreleased
----------

- Drop support for Python 3.6 and 3.7 (both are EOL)

3.1.0
-----

Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ disallow_untyped_calls = True
disallow_untyped_defs = True
follow_imports = silent
ignore_missing_imports = False
python_version = 3.6
python_version = 3.8
strict_optional = True
warn_redundant_casts = True
warn_unused_ignores = True
Expand Down
20 changes: 10 additions & 10 deletions rohrpost/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import uuid
from collections.abc import Collection, Mapping
from decimal import Decimal
from typing import Any, Dict, Union
from typing import Any, Dict, Optional, Union

from asgiref.sync import async_to_sync
from channels.generic.websocket import WebsocketConsumer
Expand Down Expand Up @@ -32,7 +32,7 @@ def send_to_group(group_name: str, message: Union[str, dict]) -> None:
"""
if async_to_sync is None:
return
async_to_sync(get_channel_layer().group_send)( # type: ignore[no-untyped-call]
async_to_sync(get_channel_layer().group_send)(
group_name, {"type": "rohrpost.message", "message": message}
)

Expand All @@ -44,10 +44,10 @@ def _send_message(*, consumer: WebsocketConsumer, content: dict) -> None:
def build_message(
*,
handler: str,
message_id: MessageID = None,
error: str = None,
message_id: Optional[MessageID] = None,
error: Optional[str] = None,
generate_id: bool = False,
data: dict = None
data: Optional[dict] = None
) -> dict:
content: Dict[str, Union[MessageID, dict]] = {}
if message_id:
Expand All @@ -68,9 +68,9 @@ def send_message(
*,
consumer: WebsocketConsumer,
handler: str,
message_id: MessageID = None,
error: str = None,
data: dict = None
message_id: Optional[MessageID] = None,
error: Optional[str] = None,
data: Optional[dict] = None
) -> None:
content = build_message(
handler=handler, message_id=message_id, error=error, data=data
Expand All @@ -86,7 +86,7 @@ def send_success(
consumer: WebsocketConsumer,
handler: str,
message_id: MessageID,
data: dict = None
data: Optional[dict] = None
) -> None:
"""
This method directly wraps send_message but checks the existence of id and type.
Expand All @@ -105,7 +105,7 @@ def send_error(
handler: str,
message_id: MessageID,
error: str,
data: dict = None
data: Optional[dict] = None
) -> None:
"""
This method wraps send_message and makes sure that error is a keyword argument.
Expand Down
16 changes: 9 additions & 7 deletions rohrpost/mixins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pylint: disable=no-member,too-few-public-methods
import json
from typing import Sequence
from typing import Optional, Sequence

from django.db.transaction import on_commit as on_transaction_commit

Expand All @@ -12,7 +12,7 @@ class NotifyBase:

def _get_group_name(self, message_type: str = "") -> str:
if hasattr(self, "get_group_name"):
return self.get_group_name(message_type=message_type) # type: ignore[attr-defined]
return self.get_group_name(message_type=message_type)
if hasattr(self, "group_name"):
return self.group_name.format(pk=self.pk) # type: ignore[attr-defined]
return "{class_name}-{pk}".format( # pylint: disable=consider-using-f-string
Expand All @@ -21,14 +21,16 @@ def _get_group_name(self, message_type: str = "") -> str:
)

def _get_push_data(
self, updated_fields: Sequence[str] = None, message_type: str = None
self,
updated_fields: Optional[Sequence[str]] = None,
message_type: Optional[str] = None,
) -> dict:
if hasattr(self, "get_push_notification_data"):
obj_data = self.get_push_notification_data( # type: ignore[attr-defined]
obj_data = self.get_push_notification_data(
updated_fields=updated_fields, message_type=message_type
)
elif hasattr(self, "serializer_class"):
obj_data = self.serializer_class(self).data # type: ignore[attr-defined]
obj_data = self.serializer_class(self).data
else:
obj_data = {"id": self.pk} # type: ignore[attr-defined]
return obj_data
Expand All @@ -39,8 +41,8 @@ def _get_message_type(self, message_type: str) -> str:
def _send_notify(
self,
message_type: str,
updated_fields: Sequence[str] = None,
data: dict = None,
updated_fields: Optional[Sequence[str]] = None,
data: Optional[dict] = None,
always_send: bool = True,
) -> None:
group_name = self._get_group_name(message_type=message_type)
Expand Down
16 changes: 7 additions & 9 deletions rohrpost/sync_consumer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import Any, Set, Union
from typing import Any, Optional, Set, Union

from asgiref.sync import async_to_sync
from channels.generic.websocket import WebsocketConsumer
Expand All @@ -21,12 +21,14 @@ def connect(self) -> None:
def disconnect(self, code: Any) -> None:
for group_name in list(self._subscribed_groups):
self._subscribed_groups.remove(group_name)
async_to_sync(self.channel_layer.group_discard)( # type: ignore[no-untyped-call]
async_to_sync(self.channel_layer.group_discard)(
group_name, self.channel_name
)
super().disconnect(code)

def receive(self, text_data: str = None, bytes_data: bytes = None) -> None:
def receive(
self, text_data: Optional[str] = None, bytes_data: Optional[bytes] = None
) -> None:
handle_rohrpost_message(consumer=self, text_data=text_data)

def rohrpost_message(self, event: dict) -> None:
Expand All @@ -49,15 +51,11 @@ def add_to_group(self, group_name: str) -> None:
if group_name in self._subscribed_groups:
return
self._subscribed_groups.add(group_name)
async_to_sync(self.channel_layer.group_add)( # type: ignore[no-untyped-call]
group_name, self.channel_name
)
async_to_sync(self.channel_layer.group_add)(group_name, self.channel_name)

def remove_from_group(self, group_name: str) -> None:
try:
self._subscribed_groups.remove(group_name)
except KeyError:
return
async_to_sync(self.channel_layer.group_discard)( # type: ignore[no-untyped-call]
group_name, self.channel_name
)
async_to_sync(self.channel_layer.group_discard)(group_name, self.channel_name)
4 changes: 1 addition & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ classifiers =
Operating System :: OS Independent
License :: OSI Approved :: MIT License
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Expand All @@ -33,7 +31,7 @@ project_urls =
packages = find_namespace:
install_requires =
channels >= 3.0
python_requires = >=3.6
python_requires = >=3.8
include_package_data = True
zip_safe = False

Expand Down

0 comments on commit 80e5ec6

Please sign in to comment.