Skip to content

fix: Fix type checker errors#1203

Open
ilotoki0804 wants to merge 6 commits intoappium:masterfrom
ilotoki0804:ilotoki0804-patch-1
Open

fix: Fix type checker errors#1203
ilotoki0804 wants to merge 6 commits intoappium:masterfrom
ilotoki0804:ilotoki0804-patch-1

Conversation

@ilotoki0804
Copy link

For a more detailed explanation, please refer to this link.

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
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 2, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.



class CanExecuteScripts(Protocol):
def pin_script(self, script: str, script_key: Optional[Any] = None) -> Any: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately this would be a breaking change

Copy link
Author

@ilotoki0804 ilotoki0804 Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. I'll implement it that way.

Copy link
Member

@KazuCocoa KazuCocoa Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

@KazuCocoa KazuCocoa Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

@KazuCocoa KazuCocoa Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warings?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opps😅

# 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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather say is deprecated for removal

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed those methods would be implemented later. If there are no plans to do so, I will make the changes as you suggested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks reasonable to me. This fixes mypy --strict also.

Copy link
Member

@KazuCocoa KazuCocoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lg to me. Waiting for the CI result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants