Skip to content

Commit 11f2ba1

Browse files
committed
chore: fix some mypy
1 parent ab6c7bb commit 11f2ba1

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

appium/webdriver/extensions/android/activities.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def wait_activity(self, activity: str, timeout: int, interval: int = 1) -> bool:
5050
`True` if the target activity is shown
5151
"""
5252
try:
53-
WebDriverWait(self, timeout, interval).until(lambda d: d.current_activity == activity)
53+
WebDriverWait(self, timeout, interval).until( # type: ignore[type-var]
54+
lambda d: d.current_activity == activity
55+
)
5456
return True
5557
except TimeoutException:
5658
return False

appium/webdriver/webdriver.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
15+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Set, Tuple, Union
1616

1717
from selenium import webdriver
1818
from selenium.common.exceptions import (
@@ -250,12 +250,15 @@ def __init__(
250250
)
251251
super().__init__(
252252
command_executor=command_executor,
253-
options=options,
253+
options=options, # type: ignore[arg-type]
254254
locator_converter=AppiumLocatorConverter(),
255255
web_element_cls=MobileWebElement,
256256
client_config=client_config,
257257
)
258258

259+
# to explicitly set type after the initialization
260+
self.command_executor: RemoteConnection
261+
259262
self._add_commands()
260263

261264
self.error_handler = MobileErrorHandler()
@@ -286,6 +289,14 @@ def __init__(
286289
method, url_cmd = instance.add_command()
287290
self.command_executor.add_command(method_name, method.upper(), url_cmd)
288291

292+
if TYPE_CHECKING:
293+
294+
def find_element(self, by: str, value: Union[str, Dict, None] = None) -> 'MobileWebElement': # type: ignore[override]
295+
...
296+
297+
def find_elements(self, by: str, value: Union[str, Dict, None] = None) -> List['MobileWebElement']: # type: ignore[override]
298+
...
299+
289300
def delete_extensions(self) -> None:
290301
"""Delete extensions added in the class with 'setattr'"""
291302
for extension in self._extensions:

appium/webdriver/webelement.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Callable, Dict, Optional, Union
15+
from typing import TYPE_CHECKING, Callable, Dict, Optional, Union
1616

1717
from selenium.webdriver.common.utils import keys_to_typing
1818
from selenium.webdriver.remote.command import Command as RemoteCommand
@@ -26,6 +26,14 @@ class WebElement(SeleniumWebElement):
2626
_execute: Callable
2727
_id: str
2828

29+
if TYPE_CHECKING:
30+
31+
def find_element(self, by: str, value: Union[str, Dict, None] = None) -> Self: # type: ignore[override]
32+
...
33+
34+
def find_elements(self, by: str, value: Union[str, Dict, None] = None) -> Self: # type: ignore[override]
35+
...
36+
2937
def get_attribute(self, name: str) -> Optional[Union[str, Dict]]: # type: ignore[override]
3038
"""Gets the given attribute or property of the element.
3139
@@ -108,7 +116,7 @@ def location_in_view(self) -> Dict[str, int]:
108116
return self._execute(Command.LOCATION_IN_VIEW)['value']
109117

110118
# Override
111-
def send_keys(self, *value: str) -> Self:
119+
def send_keys(self, *value: str) -> Self: # type: ignore[override]
112120
"""Simulates typing into the element.
113121
114122
Args:

0 commit comments

Comments
 (0)