diff --git a/README.md b/README.md index b7768faa2..4c9a8bbf7 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,24 @@ from appium import webdriver From there much of your test code will work with no change. +### Pylance/Pyright note users + +Some previously released versions of `Appium-Python-Client` may show false-positive diagnostics with strict type checking: + +- `"Remote" is not exported from module "appium.webdriver"` (`reportPrivateImportUsage`) +- `Cannot instantiate abstract class "WebDriver"` (`reportAbstractUsage`) + +You can reproduce this with [script/pylance_repro_79895384.py](script/pylance_repro_79895384.py). + +```shell +pyright script/pylance_repro_79895384.py +``` + +The current source in this repository includes a type-checking fix for the +`reportAbstractUsage` false positive. For older released versions, a practical +workaround is demonstrated in +[script/pylance_repro_79895384_workaround.py](script/pylance_repro_79895384_workaround.py). + As a base for the following code examples, the following set up the [UnitTest](https://docs.python.org/3/library/unittest.html) environment: diff --git a/appium/protocols/webdriver/can_execute_commands.py b/appium/protocols/webdriver/can_execute_commands.py index de4f1b4ad..a02692729 100644 --- a/appium/protocols/webdriver/can_execute_commands.py +++ b/appium/protocols/webdriver/can_execute_commands.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Dict, Protocol, Union +from typing import TYPE_CHECKING, Dict, Protocol, Union from selenium.webdriver.remote.remote_connection import RemoteConnection @@ -20,4 +20,5 @@ class CanExecuteCommands(Protocol): command_executor: RemoteConnection - def execute(self, driver_command: str, params: Union[Dict, None] = None) -> Dict: ... + if not TYPE_CHECKING: + def execute(self, driver_command: str, params: Union[Dict, None] = None) -> Dict: ... diff --git a/appium/protocols/webdriver/can_execute_scripts.py b/appium/protocols/webdriver/can_execute_scripts.py index 1d04f6cae..3dce79133 100644 --- a/appium/protocols/webdriver/can_execute_scripts.py +++ b/appium/protocols/webdriver/can_execute_scripts.py @@ -12,16 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Any, List, Optional, Protocol +from typing import TYPE_CHECKING, Any, List, Optional, Protocol class CanExecuteScripts(Protocol): - def pin_script(self, script: str, script_key: Optional[Any] = None) -> Any: ... + if not TYPE_CHECKING: + def execute_script(self, script: str, *args: Any) -> Any: ... - def unpin(self, script_key: Any) -> None: ... + def pin_script(self, script: str, script_key: Optional[Any] = None) -> Any: ... - def get_pinned_scripts(self) -> List[str]: ... + def unpin(self, script_key: Any) -> None: ... - def execute_script(self, script: str, *args: Any) -> Any: ... + def get_pinned_scripts(self) -> List[str]: ... - def execute_async_script(self, script: str, *args: Any) -> Any: ... + def execute_async_script(self, script: str, *args: Any) -> Any: ...