Skip to content

Commit 64e3da0

Browse files
authored
fix decorator annotation so mypy can detect proper types (#73)
* fix decorator annotation so mypy can detect proper types * cruft sync * need to pull assert_type from typing_extensions in older versions of python
1 parent 0bd699a commit 64e3da0

5 files changed

Lines changed: 34 additions & 4 deletions

File tree

.cruft.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"template": "https://github.com/ScreenPyHQ/cookiecutter_screenpy/",
3-
"commit": "6a7488b4183f615ff319dbfdac38a3a1354953c7",
3+
"commit": "74f3b6d345e1f06655a224dafb129d6c6cc035bd",
44
"checkout": null,
55
"context": {
66
"cookiecutter": {
@@ -12,7 +12,7 @@
1212
"author_email": "perry.goy@gmail.com",
1313
"github_username": "ScreenPyHQ",
1414
"_template": "https://github.com/ScreenPyHQ/cookiecutter_screenpy/",
15-
"_commit": "6a7488b4183f615ff319dbfdac38a3a1354953c7"
15+
"_commit": "74f3b6d345e1f06655a224dafb129d6c6cc035bd"
1616
}
1717
},
1818
"directory": null

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# shortcuts to help manage flipping between branches with different dependencies
22
sync:
3-
poetry install --extras dev --sync
3+
poetry sync --extras dev
44

55
update_lock_only:
66
poetry update --lock

screenpy_selenium/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
T = TypeVar("T")
1414

1515

16-
def pos_args_deprecated(*keywords: str) -> Callable:
16+
def pos_args_deprecated(*keywords: str) -> Callable[[Callable], Callable]:
1717
"""Warn users which positional arguments should be called via keyword."""
1818

1919
def deprecated(func: Callable) -> Callable:

tests/test_actions.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from selenium.webdriver.common.keys import Keys
1616
from selenium.webdriver.remote.webelement import WebElement
1717
from selenium.webdriver.support import expected_conditions as selenium_conditions
18+
from typing_extensions import assert_type
1819

1920
from screenpy_selenium import (
2021
AcceptAlert,
@@ -354,6 +355,14 @@ def test_can_be_instantiated(self) -> None:
354355
assert isinstance(e6, Enter)
355356
assert isinstance(e7, Enter)
356357
assert isinstance(e8, Enter)
358+
assert_type(e1, Enter)
359+
assert_type(e2, Enter)
360+
assert_type(e3, Enter)
361+
assert_type(e4, Enter)
362+
assert_type(e5, Enter)
363+
assert_type(e6, Enter)
364+
assert_type(e7, Enter)
365+
assert_type(e8, Enter)
357366

358367
def test_implements_protocol(self) -> None:
359368
e = Enter("")
@@ -617,6 +626,10 @@ def test_can_be_instantiated(self) -> None:
617626
assert isinstance(hd2, HoldDown)
618627
assert isinstance(hd3, HoldDown)
619628
assert isinstance(hd4, HoldDown)
629+
assert_type(hd1, HoldDown)
630+
assert_type(hd2, HoldDown)
631+
assert_type(hd3, HoldDown)
632+
assert_type(hd4, HoldDown)
620633

621634
def test_implements_protocol(self) -> None:
622635
h = HoldDown.left_mouse_button()
@@ -916,6 +929,9 @@ def test_can_be_instantiated(self) -> None:
916929
assert isinstance(r1, Release)
917930
assert isinstance(r2, Release)
918931
assert isinstance(r3, Release)
932+
assert_type(r1, Release)
933+
assert_type(r2, Release)
934+
assert_type(r3, Release)
919935

920936
def test_implements_protocol(self) -> None:
921937
r = Release.left_mouse_button()

tests/test_questions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from selenium.common.exceptions import WebDriverException
1010
from selenium.webdriver.common.alert import Alert as SeleniumAlert
1111
from selenium.webdriver.remote.webelement import WebElement
12+
from typing_extensions import assert_type
1213

1314
from screenpy_selenium import (
1415
Attribute,
@@ -274,6 +275,10 @@ def test_can_be_instantiated(self) -> None:
274275
assert isinstance(s2, Selected)
275276
assert isinstance(s3, Selected)
276277
assert isinstance(s4, Selected)
278+
assert_type(s1, Selected)
279+
assert_type(s2, Selected)
280+
assert_type(s3, Selected)
281+
assert_type(s4, Selected)
277282

278283
def test_implements_protocol(self) -> None:
279284
s = Selected(TARGET)
@@ -342,6 +347,8 @@ def test_can_be_instantiated(self) -> None:
342347

343348
assert isinstance(t1, Text)
344349
assert isinstance(t2, Text)
350+
assert_type(t1, Text)
351+
assert_type(t2, Text)
345352

346353
def test_implements_protocol(self) -> None:
347354
t = Text(TARGET)
@@ -382,6 +389,13 @@ def test_ask_for_all_text(self, Tester: Actor) -> None:
382389
def test_describe(self) -> None:
383390
assert Text(TARGET).describe() == f"The text from the {TARGET}."
384391

392+
def test_positional_arg_warns(self) -> None:
393+
with pytest.warns(
394+
DeprecationWarning,
395+
match=r".*?Please use keyword arguments instead.$",
396+
):
397+
Text(TARGET, True)
398+
385399

386400
class TestTextOfTheAlert:
387401
def test_can_be_instantiated(self) -> None:

0 commit comments

Comments
 (0)