Skip to content

Conversation

@KazuCocoa
Copy link
Member

@KazuCocoa KazuCocoa commented Aug 2, 2025

Fixes some mypy errors.

  • Add # type: ignore[override] to ignore incompatible type errors because of our lirbary's override to let users chain methods
  • Add type: ignore[arg-type] for ignorable errors for selenium lib
  • Add find_element and find_elements for typehint usage
    • The actual implementation returns the given web_element_cls=MobileWebElement so they are necessary only for typehint

After

appium/webdriver/switch_to.py:29: error: Definition of "_driver" in base class "SwitchTo" is incompatible with definition in base class "HasDriver"  [misc]

Before

$ mypy appium 
appium/webdriver/extensions/flutter_integration/flutter_finder.py:33: error: Argument 1 to "FlutterFinder" has incompatible type "str"; expected "Literal['id', 'xpath', 'link text', 'partial link text', 'name', 'tag name', 'class name', 'css selector'] | Literal['-ios predicate string', '-ios class chain', '-android uiautomator', '-android viewtag', '-android datamatcher', '-android viewmatcher', 'accessibility id', '-image', '-custom', '-flutter semantics label', '-flutter type', '-flutter key', '-flutter text containing']"  [arg-type]
appium/webdriver/extensions/flutter_integration/flutter_finder.py:37: error: Argument 1 to "FlutterFinder" has incompatible type "str"; expected "Literal['id', 'xpath', 'link text', 'partial link text', 'name', 'tag name', 'class name', 'css selector'] | Literal['-ios predicate string', '-ios class chain', '-android uiautomator', '-android viewtag', '-android datamatcher', '-android viewmatcher', 'accessibility id', '-image', '-custom', '-flutter semantics label', '-flutter type', '-flutter key', '-flutter text containing']"  [arg-type]
appium/webdriver/extensions/flutter_integration/flutter_finder.py:41: error: Argument 1 to "FlutterFinder" has incompatible type "str"; expected "Literal['id', 'xpath', 'link text', 'partial link text', 'name', 'tag name', 'class name', 'css selector'] | Literal['-ios predicate string', '-ios class chain', '-android uiautomator', '-android viewtag', '-android datamatcher', '-android viewmatcher', 'accessibility id', '-image', '-custom', '-flutter semantics label', '-flutter type', '-flutter key', '-flutter text containing']"  [arg-type]
appium/webdriver/extensions/flutter_integration/flutter_finder.py:45: error: Argument 1 to "FlutterFinder" has incompatible type "str"; expected "Literal['id', 'xpath', 'link text', 'partial link text', 'name', 'tag name', 'class name', 'css selector'] | Literal['-ios predicate string', '-ios class chain', '-android uiautomator', '-android viewtag', '-android datamatcher', '-android viewmatcher', 'accessibility id', '-image', '-custom', '-flutter semantics label', '-flutter type', '-flutter key', '-flutter text containing']"  [arg-type]
appium/webdriver/extensions/flutter_integration/flutter_finder.py:49: error: Argument 1 to "FlutterFinder" has incompatible type "str"; expected "Literal['id', 'xpath', 'link text', 'partial link text', 'name', 'tag name', 'class name', 'css selector'] | Literal['-ios predicate string', '-ios class chain', '-android uiautomator', '-android viewtag', '-android datamatcher', '-android viewmatcher', 'accessibility id', '-image', '-custom', '-flutter semantics label', '-flutter type', '-flutter key', '-flutter text containing']"  [arg-type]
appium/webdriver/webelement.py:111: error: Return type "WebElement" of "send_keys" incompatible with return type "None" in supertype "WebElement"  [override]
appium/webdriver/switch_to.py:29: error: Definition of "_driver" in base class "SwitchTo" is incompatible with definition in base class "HasDriver"  [misc]
appium/webdriver/extensions/android/activities.py:53: error: Value of type variable "D" of "WebDriverWait" cannot be "Activities"  [type-var]
appium/webdriver/webdriver.py:212: error: Definition of "command_executor" in base class "WebDriver" is incompatible with definition in base class "CanExecuteCommands"  [misc]
appium/webdriver/webdriver.py:253: error: Argument "options" to "__init__" of "WebDriver" has incompatible type "AppiumOptions | list[AppiumOptions] | None"; expected "BaseOptions | list[BaseOptions] | None"  [arg-type]
appium/webdriver/webdriver.py:267: error: "type[By]" has no attribute "IOS_PREDICATE"  [attr-defined]
appium/webdriver/webdriver.py:268: error: "type[By]" has no attribute "IOS_CLASS_CHAIN"  [attr-defined]
appium/webdriver/webdriver.py:269: error: "type[By]" has no attribute "ANDROID_UIAUTOMATOR"  [attr-defined]
appium/webdriver/webdriver.py:270: error: "type[By]" has no attribute "ANDROID_VIEWTAG"  [attr-defined]
appium/webdriver/webdriver.py:271: error: "type[By]" has no attribute "ACCESSIBILITY_ID"  [attr-defined]
appium/webdriver/webdriver.py:272: error: "type[By]" has no attribute "IMAGE"  [attr-defined]
appium/webdriver/webdriver.py:273: error: "type[By]" has no attribute "CUSTOM"  [attr-defined]
appium/webdriver/webdriver.py:279: error: "WebDriver" not callable  [operator]
appium/webdriver/webdriver.py:287: error: Item "str" of "str | RemoteConnection" has no attribute "add_command"  [union-attr]
appium/webdriver/webdriver.py:292: error: "WebDriver" not callable  [operator]
appium/webdriver/webdriver.py:480: error: Item "str" of "str | RemoteConnection" has no attribute "add_command"  [union-attr]
appium/webdriver/webdriver.py:483: error: Item "str" of "str | RemoteConnection" has no attribute "add_command"  [union-attr]
appium/webdriver/webdriver.py:484: error: Item "str" of "str | RemoteConnection" has no attribute "add_command"  [union-attr]
appium/webdriver/webdriver.py:491: error: Item "str" of "str | RemoteConnection" has no attribute "add_command"  [union-attr]
appium/webdriver/webdriver.py:492: error: Item "str" of "str | RemoteConnection" has no attribute "add_command"  [union-attr]
appium/webdriver/webdriver.py:494: error: Item "str" of "str | RemoteConnection" has no attribute "add_command"  [union-attr]
appium/webdriver/webdriver.py:495: error: Item "str" of "str | RemoteConnection" has no attribute "add_command"  [union-attr]
appium/webdriver/extensions/flutter_integration/flutter_commands.py:295: error: Dict entry 0 has incompatible type "str": "WebElement"; expected "str": "dict[Any, Any]"  [dict-item]

@KazuCocoa KazuCocoa changed the title chore: fix some mypy chore: fix some mypy errors Aug 7, 2025
@KazuCocoa KazuCocoa marked this pull request as ready for review August 7, 2025 00:06
@KazuCocoa KazuCocoa requested a review from Copilot August 7, 2025 00:06

This comment was marked as outdated.

KazuCocoa and others added 3 commits August 7, 2025 09:29
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@KazuCocoa KazuCocoa requested a review from Copilot August 7, 2025 01:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses mypy type checking errors throughout the Appium codebase. The changes primarily involve adding type annotations, type ignore directives, and type casting to resolve type compatibility issues with the library's method chaining patterns and selenium integration.

Key changes:

  • Added # type: ignore[override] directives to allow method chaining return types that differ from Selenium's base classes
  • Introduced type casting with cast() to resolve argument type mismatches in Flutter integration
  • Added TYPE_CHECKING blocks with stub methods for improved type hinting

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
appium/webdriver/webelement.py Adds TYPE_CHECKING block with find_element/find_elements stubs and override annotation for send_keys
appium/webdriver/webdriver.py Adds TYPE_CHECKING block with find methods, fixes extensions parameter type, and adds command_executor annotation
appium/webdriver/extensions/flutter_integration/flutter_finder.py Uses cast() to resolve AppiumBy constant type mismatches
appium/webdriver/extensions/flutter_integration/flutter_commands.py Updates return type annotation to include WebElement in union
appium/webdriver/extensions/android/activities.py Adds type ignore for WebDriverWait type variable issue
appium/webdriver/common/appiumby.py Adds missing '-flutter text' constant to AppiumByType list

'-flutter semantics label',
'-flutter type',
'-flutter key',
'-flutter text',
Copy link

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

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

Adding '-flutter text' to the AppiumByType list appears inconsistent with the existing Flutter constants. The other Flutter constants follow a pattern like '-flutter semantics label', '-flutter type', '-flutter key', but there's no corresponding AppiumBy.FLUTTER_INTEGRATION_TEXT constant visible in the context.

Copilot uses AI. Check for mistakes.
@KazuCocoa
Copy link
Member Author

I'll merge this to publish a patch, then moving to #1155

@KazuCocoa KazuCocoa merged commit 4e1aafd into master Aug 7, 2025
11 checks passed
@KazuCocoa KazuCocoa deleted the for-mypy branch August 7, 2025 02:22
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.

2 participants