Skip to content

Commit 895cde1

Browse files
refactor: Update types descriptions for mixin classes (appium#677)
1 parent 72f942d commit 895cde1

52 files changed

Lines changed: 591 additions & 622 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pytest = "~=6.2"
1515
pytest-cov = "~=3.0"
1616

1717
tox = "~=3.24"
18+
typing-extensions = "~=4.0"
1819

1920
httpretty = "~=1.1"
2021
python-dateutil = "~=2.8"

appium/common/exceptions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@ class NoSuchContextException(InvalidSwitchToTargetException):
2424
print(driver.contexts)
2525
2626
"""
27-
28-
pass

appium/common/helper.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ def extract_const_attributes(cls: type) -> Dict[str, Any]:
2626
Returns:
2727
dict with constants attributes and values in the class
2828
"""
29-
return dict(
30-
[(attr, value) for attr, value in vars(cls).items() if not callable(getattr(cls, attr)) and attr.isupper()]
31-
)
29+
return {attr: value for attr, value in vars(cls).items() if not callable(getattr(cls, attr)) and attr.isupper()}
3230

3331

3432
def library_version() -> str:

appium/protocols/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

appium/protocols/protocol.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import sys
16+
17+
if sys.version_info >= (3, 8):
18+
# noinspection PyUnresolvedReferences
19+
from typing import Protocol
20+
else:
21+
# noinspection PyUnresolvedReferences
22+
from typing_extensions import Protocol
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from typing import Dict
16+
17+
from selenium.webdriver.remote.remote_connection import RemoteConnection
18+
19+
from ..protocol import Protocol
20+
21+
22+
class CanExecuteCommands(Protocol):
23+
command_executor: RemoteConnection
24+
25+
def execute(self, driver_command: str, params: Dict = None) -> Dict:
26+
...
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from typing import Any, List, Optional
16+
17+
from ..protocol import Protocol
18+
19+
20+
class CanExecuteScripts(Protocol):
21+
def pin_script(self, script: str, script_key: Optional[Any] = None) -> Any:
22+
...
23+
24+
def unpin(self, script_key: Any) -> None:
25+
...
26+
27+
def get_pinned_scripts(self) -> List[str]:
28+
...
29+
30+
def execute_script(self, script: str, *args: Any) -> Any:
31+
...
32+
33+
def execute_async_script(self, script: str, *args: Any) -> Any:
34+
...

appium/webdriver/extensions/search_context/base_search_context.py renamed to appium/protocols/webdriver/can_find_elements.py

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

15-
# pylint: disable=abstract-method
16-
1715
from typing import TYPE_CHECKING, Dict, List, Union
1816

17+
from ..protocol import Protocol
18+
1919
if TYPE_CHECKING:
2020
from appium.webdriver.webelement import WebElement
2121

2222

23-
class BaseSearchContext:
24-
"""Used by each search context. Dummy find_element/s are for preventing pylint error"""
25-
23+
class CanFindElements(Protocol):
2624
def find_element(self, by: str, value: Union[str, Dict] = None) -> 'WebElement':
27-
raise NotImplementedError
25+
...
2826

2927
def find_elements(self, by: str, value: Union[str, Dict] = None) -> List['WebElement']:
30-
raise NotImplementedError
28+
...

appium/webdriver/appium_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _get_connection_manager(self) -> Union[urllib3.PoolManager, urllib3.ProxyMan
4646
def get_remote_connection_headers(cls, parsed_url: 'ParseResult', keep_alive: bool = True) -> Dict[str, Any]:
4747
"""Override get_remote_connection_headers in RemoteConnection"""
4848
headers = RemoteConnection.get_remote_connection_headers(parsed_url, keep_alive=keep_alive)
49-
headers['User-Agent'] = 'appium/python {} ({})'.format(library_version(), headers['User-Agent'])
49+
headers['User-Agent'] = f'appium/python {library_version()} ({headers["User-Agent"]})'
5050
if parsed_url.path.endswith('/session'):
5151
# https://github.com/appium/appium-base-driver/pull/400
5252
headers['X-Idempotency-Key'] = str(uuid.uuid4())

0 commit comments

Comments
 (0)