Conversation
In `py.typed` modules, imported symbols considered private[^1], which is not importable by users. To become public interface, explicit `__all__` symbol is required. [^1]: https://typing.python.org/en/latest/spec/distributing.html#library-interface-public-and-private-symbols
|
|
||
|
|
||
| class CanExecuteScripts(Protocol): | ||
| def pin_script(self, script: str, script_key: Optional[Any] = None) -> Any: ... |
There was a problem hiding this comment.
unfortunately this would be a breaking change
There was a problem hiding this comment.
As I understand it, the four commented-out methods are methods that were never defined or used anywhere in the module.
Since these methods were never actually implemented, it appears they would have served no practical purpose if a user attempted to use them.
However, while it's true they did nothing, it's also true they didn't cause any errors. Therefore, technically, it does not guarantee backward compatibility. If backward compatibility of the code is a concern, instead of commenting them out, I could add if not TYPE_CHECKING to those methods. This would preserve backward compatibility while avoiding sending incorrect signals to static type checkers (though the issue would persist at runtime). Would you prefer that approach?
There was a problem hiding this comment.
yes, that approach makes more sense if we want to make the change non-breaking
It may also make sense to mark these fields as deprecated so they could be removed after the next major version bump
WDYT @KazuCocoa ?
There was a problem hiding this comment.
Alright. I'll implement it that way.
There was a problem hiding this comment.
If I remember correctly, the original motivation for this was to give typehint for methods existed in selneium:
https://github.com/SeleniumHQ/selenium/blob/6c60a108ce7fdc3f537e62c4060c998f3cdb5c5f/py/selenium/webdriver/remote/webdriver.py#L480 as well.
So Appium Python client itself doesn't have the implementation, but their actual behavior comes from Selenium Python Binding. Appium Python client simply provides the type hint to help users to tell these hints for Web automation.
These scripts are not deprecated since selenium binging has - which is parents of this python client
There was a problem hiding this comment.
I wondered if we can simply remove them since the parent selenium project already have type hints for them today. Editors can refer to the parent selenium.
[update]
Maybe the primary usage for these types are in this repository development purpose
There was a problem hiding this comment.
Would #1204 help...?
Not sure if the PR error case is the actual reason, but on this project basis, the selenium deps is installed in the venv. If I have specified pyright config (which is pylance's code analytics) the error stopped.
Also, mypy doesn't have this behavior, so possibly this is pyright specific behavior, which might expect protocol-defined methods would be implemented in the children only (not parents)
There was a problem hiding this comment.
After digging deeper based on your feedback, I found an issue where selenium.webdriver.Remote wasn't being recognized correctly in Pyright. However, if you import and use selenium.webdriver.remote.webdriver.Webdriver instead of selenium.webdriver.Remote, pyright correctly discovers the class, and that class properly implements the methods in the protocol, resolving the issue. I'm not sure whether this error was caused by pyright or selenium's implementation.
I reverted the protocol implementation and changed the import path.
BTW at least in my setup, trying #1204 didn't resolve the issue. I suspect that wasn't the solution to the main cause.
There was a problem hiding this comment.
mypy is a reference checker for PEP 484 and it might not have this issue. So, it could be pyright specific behavior (not sure this is an issue, though)
https://docs.basedpyright.com/dev/usage/mypy-comparison/?utm_source=copilot.com
Added deprecation warnings for unimplemented methods in CanExecuteScripts protocol.
|
|
||
| from typing import Any, List, Optional, Protocol | ||
| from typing import Any, List, Optional, Protocol, TYPE_CHECKING | ||
| from warings import deprecated |
| # TODO: remove `if not TYPE_CHECKING` guard after properly implement them | ||
| # The use of these methods will produce DeprecationWarnings at runtime | ||
| if not TYPE_CHECKING: | ||
| @deprecated("pin_script is not yet implemented") |
There was a problem hiding this comment.
I would rather say is deprecated for removal
There was a problem hiding this comment.
I assumed those methods would be implemented later. If there are no plans to do so, I will make the changes as you suggested.
There was a problem hiding this comment.
I am not sure it makes sense to implement them in mobile context, but it still makes sense to confirm that with other maintainers
| Appium Python Client: WebDriver module | ||
| """ | ||
|
|
||
| __all__ = ["Remote", "WebElement"] |
There was a problem hiding this comment.
This change looks reasonable to me. This fixes mypy --strict also.
KazuCocoa
left a comment
There was a problem hiding this comment.
Lg to me. Waiting for the CI result
For a more detailed explanation, please refer to this link.