Skip to content

Commit 6343109

Browse files
committed
fix decorator annotation so mypy can detect proper types
1 parent 0bd699a commit 6343109

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import warnings
55
from contextlib import contextmanager
66
from pathlib import Path
7-
from typing import TYPE_CHECKING, cast
7+
from typing import TYPE_CHECKING, assert_type, cast
88
from unittest import mock
99

1010
import pytest
@@ -354,6 +354,14 @@ def test_can_be_instantiated(self) -> None:
354354
assert isinstance(e6, Enter)
355355
assert isinstance(e7, Enter)
356356
assert isinstance(e8, Enter)
357+
assert_type(e1, Enter)
358+
assert_type(e2, Enter)
359+
assert_type(e3, Enter)
360+
assert_type(e4, Enter)
361+
assert_type(e5, Enter)
362+
assert_type(e6, Enter)
363+
assert_type(e7, Enter)
364+
assert_type(e8, Enter)
357365

358366
def test_implements_protocol(self) -> None:
359367
e = Enter("")
@@ -617,6 +625,10 @@ def test_can_be_instantiated(self) -> None:
617625
assert isinstance(hd2, HoldDown)
618626
assert isinstance(hd3, HoldDown)
619627
assert isinstance(hd4, HoldDown)
628+
assert_type(hd1, HoldDown)
629+
assert_type(hd2, HoldDown)
630+
assert_type(hd3, HoldDown)
631+
assert_type(hd4, HoldDown)
620632

621633
def test_implements_protocol(self) -> None:
622634
h = HoldDown.left_mouse_button()
@@ -916,6 +928,9 @@ def test_can_be_instantiated(self) -> None:
916928
assert isinstance(r1, Release)
917929
assert isinstance(r2, Release)
918930
assert isinstance(r3, Release)
931+
assert_type(r1, Release)
932+
assert_type(r2, Release)
933+
assert_type(r3, Release)
919934

920935
def test_implements_protocol(self) -> None:
921936
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)