Conversation
For a variadic parameter, the annotation types each individual argument, not the collection they're gathered into -- *devices: str means "each positional arg is a str", matching how add_output_devices/ remove_output_devices/set_output_devices are actually called (with individual device ID strings unpacked via *) and how they're implemented (each element treated as one string, never a list). Same bug in four places: the abstract declarations in interface.py, the facade relay in core/facade.py, the MRP protocol implementation in protocols/mrp/__init__.py, and the underlying protobuf message builders in protocols/mrp/messages.py. Fixes postlund#2828 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
Closes #2828. For a variadic parameter, the annotation types each individual argument, not the collection they get gathered into at the call site --
*devices: strmeans "each positional arg is astr", matching how these functions are actually called (set_output_devices(*device_ids)with a list of individual device ID strings unpacked via*) and how they're implemented internally (each element treated as one string, never a list, at every call site in this codebase).Same bug in four places, all fixed the same way:
pyatv/interface.py-- the three abstract declarations (add_output_devices,remove_output_devices,set_output_devices)pyatv/core/facade.py-- the facade relay, which just forwards*devicesunchangedpyatv/protocols/mrp/__init__.py-- the MRP protocol implementationpyatv/protocols/mrp/messages.py-- the underlying protobuf message builders (add_output_devices/remove_output_devices/set_output_devices), which iteratedevice_uidsand append each one individually to a repeated protobuf field -- one more instance of the same mistake the issue didn't call out, found while checking every call siteListbecame an unused import inmessages.pyafter the fix; removed.Testing
This is a pure static-typing annotation fix with no runtime behavior change, so verification is via mypy, not pytest assertions:
*devices: List[str]class definition, called the way the issue describes, gives mypy's exact reported message (incompatible type "*list[str]"; expected "list[str]"). The same pattern with*devices: strtype-checks clean.mypy(the project's ownpyatv --ignore-missing-imports --follow-imports=skipinvocation fromchickn.yaml) before and after on the fullpyatvpackage: 14 pre-existing, unrelated errors in both runs (indns.py,http.py,metadata.py,pairing.py,scan.py, one line ofmrp/__init__.pyunrelated to output devices, and__init__.py) -- none of them ever mentionoutput_devices, and the count and file list are identical before/after this change.test_scan_with_zeroconf_complete_and_device_info_specific_host_matching, anIndexErrorthat reproduces identically on unmodifiedmain-- confirmed viagit stashbefore/after), 6 skipped.black --check,flake8, andpylint(10.00/10) all clean on the four changed files.🤖 Generated with Claude Code