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

Strict typing and link issues #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions jaraco/pmxbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from pmxbot.core import command


@command("resolv", doc="resolve a hostname")
def resolve(rest):
@command("resolv", doc="resolve a hostname") # type: ignore[misc] # pmxbot/pmxbot#113
def resolve(rest: str) -> str:
"""
>>> resolve("localhost")
'...'
Expand Down
18 changes: 10 additions & 8 deletions jaraco/pmxbot/notification.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from __future__ import annotations

import re

import twilio.rest

import pmxbot
from pmxbot.core import command


from_number = '+15712573984'


@command()
def send_text(rest):
@command() # type: ignore[misc] # pmxbot/pmxbot#113
def send_text(rest: str) -> str | None:
"""
Send an SMS message: pass the phone number and message to send.
"""
Expand All @@ -18,17 +20,17 @@ def send_text(rest):
number, _, msg = rest.partition(' ')
number = parse_number(number)
if not msg:
return
msg = msg.encode('ascii')[:160]
return None
encoded_msg = msg.encode('ascii')[:160]
client = twilio.rest.Client(username=account, password=token)
client.messages.create(to=number, from_=from_number, body=msg)
client.messages.create(to=number, from_=from_number, body=encoded_msg)
return "Sent {count} chars to {number}".format(
count=len(msg),
count=len(encoded_msg),
number=number,
)


def parse_number(input_):
def parse_number(input_: str) -> str:
"""
Strip everything but digits and + sign; ensure it begins with a country
code.
Expand Down
Empty file added jaraco/pmxbot/py.typed
Empty file.
10 changes: 9 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[mypy]
# Is the project well-typed?
strict = False
strict = True

# Early opt-in even when strict = False
warn_unused_ignores = True
Expand All @@ -13,3 +13,11 @@ explicit_package_bases = True
disable_error_code =
# Disable due to many false positives
overload-overlap,

# pmxbot/pmxbot#113
[mypy-pmxbot.*]
ignore_missing_imports = True

# twilio/twilio-python#568
[mypy-twilio.*]
ignore_missing_imports = True
1 change: 1 addition & 0 deletions newsfragments/6.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Complete annotations and add ``py.typed`` marker -- by :user:`Avasam`
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,3 @@ notification = "jaraco.pmxbot.notification"


[tool.setuptools_scm]


[tool.pytest-enabler.mypy]
# Disabled due to jaraco/skeleton#143
16 changes: 10 additions & 6 deletions tests/test_notification.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import pytest
from typing import Dict

import pmxbot
from jaraco.collections import ItemsAsAttributes
import pytest

from jaraco.collections import ItemsAsAttributes
from jaraco.pmxbot import notification


@pytest.fixture
def twilio_test_credentials(monkeypatch):
class ConfigDict(ItemsAsAttributes, dict):
def twilio_test_credentials(monkeypatch: pytest.MonkeyPatch) -> None:
class ConfigDict(ItemsAsAttributes, Dict[str, str]):
pass

monkeypatch.setattr(pmxbot, 'config', ConfigDict(), raising=False)
Expand All @@ -24,10 +26,12 @@ class ConfigDict(ItemsAsAttributes, dict):
monkeypatch.setattr(notification, 'from_number', '+15005550006')


def test_send_text(twilio_test_credentials):
@pytest.mark.usefixtures("twilio_test_credentials")
def test_send_text() -> None:
res = notification.send_text(rest='+12026837967 <3 pmxbot')
assert res == 'Sent 9 chars to +12026837967'


def test_no_message(twilio_test_credentials):
@pytest.mark.usefixtures("twilio_test_credentials")
def test_no_message() -> None:
assert not notification.send_text(rest='')
Loading