1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- from typing import List , Optional , Tuple , TypeVar
15+ from typing import TYPE_CHECKING , List , Optional , Tuple , cast
1616
1717from selenium .webdriver .common .action_chains import ActionChains
1818from selenium .webdriver .common .actions import interaction
1919from selenium .webdriver .common .actions .action_builder import ActionBuilder
2020from selenium .webdriver .common .actions .mouse_button import MouseButton
2121from selenium .webdriver .common .actions .pointer_input import PointerInput
2222
23- from appium .protocols .webdriver .can_execute_commands import CanExecuteCommands
2423from appium .webdriver .webelement import WebElement
2524
26- T = TypeVar ('T' , bound = CanExecuteCommands )
25+ if TYPE_CHECKING :
26+ from appium .webdriver .webdriver import WebDriver
2727
2828
2929class ActionHelpers :
30- def scroll (self : T , origin_el : WebElement , destination_el : WebElement , duration : Optional [int ] = None ) -> T :
30+ def scroll (self , origin_el : WebElement , destination_el : WebElement , duration : Optional [int ] = None ) -> 'WebDriver' :
3131 """Scrolls from one element to another
3232
3333 Args:
@@ -59,9 +59,9 @@ def scroll(self: T, origin_el: WebElement, destination_el: WebElement, duration:
5959 actions .w3c_actions .pointer_action .move_to (destination_el )
6060 actions .w3c_actions .pointer_action .release ()
6161 actions .perform ()
62- return self
62+ return cast ( 'WebDriver' , self )
6363
64- def drag_and_drop (self : T , origin_el : WebElement , destination_el : WebElement ) -> T :
64+ def drag_and_drop (self , origin_el : WebElement , destination_el : WebElement ) -> 'WebDriver' :
6565 """Drag the origin element to the destination element
6666
6767 Args:
@@ -77,9 +77,9 @@ def drag_and_drop(self: T, origin_el: WebElement, destination_el: WebElement) ->
7777 actions .w3c_actions .pointer_action .move_to (destination_el )
7878 actions .w3c_actions .pointer_action .release ()
7979 actions .perform ()
80- return self
80+ return cast ( 'WebDriver' , self )
8181
82- def tap (self : T , positions : List [Tuple [int , int ]], duration : Optional [int ] = None ) -> T :
82+ def tap (self , positions : List [Tuple [int , int ]], duration : Optional [int ] = None ) -> 'WebDriver' :
8383 """Taps on an particular place with up to five fingers, holding for a
8484 certain time
8585
@@ -127,9 +127,9 @@ def tap(self: T, positions: List[Tuple[int, int]], duration: Optional[int] = Non
127127 new_input .create_pause (0.1 )
128128 new_input .create_pointer_up (MouseButton .LEFT )
129129 actions .perform ()
130- return self
130+ return cast ( 'WebDriver' , self )
131131
132- def swipe (self : T , start_x : int , start_y : int , end_x : int , end_y : int , duration : int = 0 ) -> T :
132+ def swipe (self , start_x : int , start_y : int , end_x : int , end_y : int , duration : int = 0 ) -> 'WebDriver' :
133133 """Swipe from one point to another point, for an optional duration.
134134
135135 Args:
@@ -156,9 +156,9 @@ def swipe(self: T, start_x: int, start_y: int, end_x: int, end_y: int, duration:
156156 actions .w3c_actions .pointer_action .move_to_location (end_x , end_y )
157157 actions .w3c_actions .pointer_action .release ()
158158 actions .perform ()
159- return self
159+ return cast ( 'WebDriver' , self )
160160
161- def flick (self : T , start_x : int , start_y : int , end_x : int , end_y : int ) -> T :
161+ def flick (self , start_x : int , start_y : int , end_x : int , end_y : int ) -> 'WebDriver' :
162162 """Flick from one point to another point.
163163
164164 Args:
@@ -180,4 +180,4 @@ def flick(self: T, start_x: int, start_y: int, end_x: int, end_y: int) -> T:
180180 actions .w3c_actions .pointer_action .move_to_location (end_x , end_y )
181181 actions .w3c_actions .pointer_action .release ()
182182 actions .perform ()
183- return self
183+ return cast ( 'WebDriver' , self )
0 commit comments