Repository navigation
Conversation
find_image_occurrence and get_images_similarity were annotated as returning dict[str, bytes | dict], and get_events as returning dict[str, str | int]. None of these match what the server sends. The images plugin (packages/images-plugin/lib/compare.ts in appium/appium) returns the score as a number and the visualization as a base64 string, and with the multiple option find_image_occurrence returns a list of matches instead of a single dict. The base driver event log (packages/base-driver/lib/basedriver/core.ts) stores every event as a list: `commands` holds dicts with cmd, startTime and endTime, and each other key holds a list of millisecond timestamps. Annotate find_image_occurrence as dict[str, Any] | list[dict[str, Any]], get_images_similarity as dict[str, Any] and get_events as dict[str, Any]. The docstrings now describe visualization as a str, document the multiple option, the score entry and the list result, and describe the event lists. The same visualization and points types are corrected in match_images_features, and a `boo` typo is fixed. There is no runtime change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Three methods have return annotations that do not match what the server sends:
find_image_occurrence()andget_images_similarity()are annotated-> dict[str, bytes | dict]. The images plugin (packages/images-plugin/lib/compare.ts) returnsscoreas a number and convertsvisualizationto a base64 string. When themultipleoption is set,find_image_occurrence()returns a list of matches instead of a dict.get_events()is annotated-> dict[str, str | int]. The base driver (packages/base-driver/lib/basedriver/core.tsanddriver.ts) stores every value as a list.commandsis a list of{cmd, startTime, endTime}dicts, and every other key is a list of millisecond timestamps. The existing unit test already uses{'appium:funEvent': [12347]}.As a result, mypy rejects correct code. For example,
score: float = driver.get_images_similarity(a, b)['score']fails withexpression has type "bytes | dict[Any, Any]", andfor c in driver.get_events()['commands']fails withItem "int" of "str | int" has no attribute "__iter__".The docstrings also describe
visualizationasbytes, do not mentionmultipleor the list result, and do not say that event values are lists.Fix
find_image_occurrence()as-> dict[str, Any] | list[dict[str, Any]].get_images_similarity()andget_events()as-> dict[str, Any].visualizationas a base64str, document themultipleoption, thescoreentry and the list result, and say that every event value is a list.match_images_features(), which already returnsdict[str, Any], correct the samevisualization (bytes)entry and describepoints1andpoints2as lists, as inMatchingResultinpackages/opencv/lib/types.ts. Also fix avisualize (boo)typo.There is no runtime change.
Behaviour change: type-checker results change. The examples above now pass. Code that indexes the result of
find_image_occurrence()directly now needs to narrow it first, for example withisinstance(result, dict). Onmasterthe same code was already rejected, becausebytescannot be indexed with a string.Tests
masterit reports three errors: thescoreassignment, iteratingevents['commands'], and indexing a command dict. With this change it reports none, andfind_image_occurrence(..., multiple=True)is revealed asdict[str, Any] | list[dict[str, Any]].ruff check,ruff format --check,mypy appiumand the full unit test suite pass.🤖 Generated with Claude Code