Skip to content

Commit

Permalink
Merge pull request #201 from nnsnodnb/update-mypy-job
Browse files Browse the repository at this point in the history
Update mypy job on CI
  • Loading branch information
nnsnodnb committed Jan 30, 2024
2 parents 397f5be + 5485807 commit 9545b81
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,22 @@ jobs:
python-version: ['3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up Python environment
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
- name: Install dependencies
run: poetry install --sync --with dev --no-root
- name: mypy
uses: tsuyoshicho/action-mypy@v4
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
level: warning
execute_command: poetry run mypy --config-file mypy.ini .

isort:
runs-on: ubuntu-latest
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ asyncio.run(

### LiveActivity

> [!NOTE]
> - The topic suffix must be `.push-type.liveactivity`.
> - `LiveActivityPayload.event` default value is `LiveActivityEvent.UPDATE`.
```python
import asyncio
from datetime import datetime
Expand Down Expand Up @@ -97,6 +101,9 @@ asyncio.run(

### VoIP

> [!NOTE]
> - The topic suffix must be `.voip`.
```python
import asyncio
from pathlib import Path
Expand Down
9 changes: 6 additions & 3 deletions kalyke/clients/live_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ class LiveActivityClient(ApnsClient):
async def send_message(
self,
device_token: str,
payload: Union[LiveActivityPayload, Dict[str, Any]],
apns_config: LiveActivityApnsConfig,
payload: Union[LiveActivityPayload, Dict[str, Any]], # type: ignore[override]
apns_config: LiveActivityApnsConfig, # type: ignore[override]
) -> str:
return await super().send_message(
device_token=device_token,
payload=payload,
apns_config=apns_config,
)

def _init_client(self, apns_config: LiveActivityApnsConfig) -> AsyncClient:
def _init_client(
self,
apns_config: LiveActivityApnsConfig, # type: ignore[override]
) -> AsyncClient:
return super()._init_client(apns_config=apns_config)
9 changes: 6 additions & 3 deletions kalyke/clients/voip.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ def __post_init__(self) -> None:
async def send_message(
self,
device_token: str,
payload: Dict[str, Any],
apns_config: VoIPApnsConfig,
payload: Dict[str, Any], # type: ignore[override]
apns_config: VoIPApnsConfig, # type: ignore[override]
) -> str:
return await super().send_message(
device_token=device_token,
payload=payload,
apns_config=apns_config,
)

def _init_client(self, apns_config: VoIPApnsConfig) -> AsyncClient:
def _init_client(
self,
apns_config: VoIPApnsConfig, # type: ignore[override]
) -> AsyncClient:
headers = apns_config.make_headers()
context = httpx.create_ssl_context()
context.load_cert_chain(
Expand Down
6 changes: 2 additions & 4 deletions kalyke/models/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,15 @@ def dict(self) -> Dict[str, Any]:
@dataclass(frozen=True)
class LiveActivityPayload(Payload):
timestamp: datetime = field(default_factory=datetime.now)
event: LiveActivityEvent = field(default=None)
event: LiveActivityEvent = field(default=LiveActivityEvent.UPDATE)
content_state: Dict[str, Any] = field(default_factory=dict)
stale_date: Optional[datetime] = field(default=None)
dismissal_date: Optional[datetime] = field(default=None)
attributes_type: Optional[str] = field(default=None)
attributes: Optional[Dict[str, Any]] = field(default=None)

def __post_init__(self):
if self.event is None:
raise ValueError("event must be specified.")
elif self.event == LiveActivityEvent.START:
if self.event == LiveActivityEvent.START:
self._validate_event_is_start()
try:
_ = json.dumps(self.content_state)
Expand Down
7 changes: 0 additions & 7 deletions tests/models/payload/test_live_activity_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
from kalyke import InterruptionLevel, LiveActivityEvent, LiveActivityPayload, PayloadAlert, exceptions


def test_live_activity_payload_event_is_not_event_value_error():
with pytest.raises(ValueError) as e:
_ = LiveActivityPayload()

assert str(e.value) == "event must be specified."


@pytest.mark.parametrize(
"attributes_type, attributes",
[
Expand Down

0 comments on commit 9545b81

Please sign in to comment.