fix False negative: Pyrefly does not emit an unpacking error in for k, v in dict #3352#3353
fix False negative: Pyrefly does not emit an unpacking error in for k, v in dict #3352#3353asukaminato0721 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a false-negative where tuple-unpacking in for loop targets did not report an unpacking error when the iterated element type was string-like (e.g., dict key iteration yielding str), by adding a string-like guard to unpack-length checking and updating/adding regression tests.
Changes:
- Add
is_string_likehelper and emitbad-unpackingwhen unpack-length checking is applied to string-like types. - Update existing string-literal unpacking tests to assert the expected error.
- Add a new regression test covering
for k, v in {"x": 1}andfor a, b in list[str].
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pyrefly/lib/alt/solve.rs | Add string-like detection and produce BadUnpacking in BindingExpect::UnpackedLength for string-like types. |
| pyrefly/lib/test/assign.rs | Update existing unpack-string tests and add for-loop unpacking regression coverage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
the added errors for apprise look fishy, both of them are typed as |
|
|
Diff from mypy_primer, showing the effect of this PR on open source code: apprise (https://github.com/caronc/apprise)
- ERROR apprise/plugins/xmpp/adapter.py:161:31-47: Expected 1 type argument for `list`, got 2 [bad-specialization]
- ERROR apprise/plugins/xmpp/adapter.py:350:18-34: Expected 1 type argument for `list`, got 2 [bad-specialization]
- ERROR apprise/plugins/xmpp/adapter.py:863:18-34: Expected 1 type argument for `list`, got 2 [bad-specialization]
- ERROR apprise/plugins/xmpp/adapter.py:911:27-43: Expected 1 type argument for `list`, got 2 [bad-specialization]
- ERROR apprise/plugins/xmpp/base.py:175:27-43: Expected 1 type argument for `list`, got 2 [bad-specialization]
- ERROR apprise/plugins/xmpp/base.py:202:23-39: Expected 1 type argument for `list`, got 2 [bad-specialization]
- ERROR apprise/plugins/xmpp/base.py:218:33-45: Argument `tuple[Literal['chat', 'groupchat'], str]` is not assignable to parameter `object` with type `str` in function `list.append` [bad-argument-type]
+ ERROR tests/test_plugin_xmpp.py:280:17-76: Argument `list[str]` is not assignable to parameter `targets` with type `list[tuple[str, str]] | None` in function `apprise.plugins.xmpp.base.NotifyXMPP.__init__` [bad-argument-type]
+ ERROR tests/test_plugin_xmpp.py:303:17-51: Argument `list[str]` is not assignable to parameter `targets` with type `list[tuple[str, str]] | None` in function `apprise.plugins.xmpp.base.NotifyXMPP.__init__` [bad-argument-type]
+ ERROR tests/test_plugin_xmpp.py:315:17-34: Argument `list[str]` is not assignable to parameter `targets` with type `list[tuple[str, str]] | None` in function `apprise.plugins.xmpp.base.NotifyXMPP.__init__` [bad-argument-type]
+ ERROR tests/test_plugin_xmpp.py:363:17-28: Argument `list[str]` is not assignable to parameter `targets` with type `list[tuple[str, str]] | None` in function `apprise.plugins.xmpp.base.NotifyXMPP.__init__` [bad-argument-type]
+ ERROR tests/test_plugin_xmpp.py:445:17-24: Argument `list[str]` is not assignable to parameter `targets` with type `list[tuple[str, str]] | None` in function `apprise.plugins.xmpp.base.NotifyXMPP.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:762:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:784:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:794:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:847:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:875:17-71: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:933:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:1068:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:1169:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:1259:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:1353:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:1392:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:1446:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:1512:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
+ ERROR tests/test_plugin_xmpp.py:1569:17-34: Argument `list[str]` is not assignable to parameter `targets` with type `list[tuple[str, str]] | None` in function `apprise.plugins.xmpp.base.NotifyXMPP.__init__` [bad-argument-type]
+ ERROR tests/test_plugin_xmpp.py:1611:17-34: Argument `list[str]` is not assignable to parameter `targets` with type `list[tuple[str, str]] | None` in function `apprise.plugins.xmpp.base.NotifyXMPP.__init__` [bad-argument-type]
+ ERROR tests/test_plugin_xmpp.py:1630:17-34: Argument `list[str]` is not assignable to parameter `targets` with type `list[tuple[str, str]] | None` in function `apprise.plugins.xmpp.base.NotifyXMPP.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:1654:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
+ ERROR tests/test_plugin_xmpp.py:1669:35-40: Argument `list[str]` is not assignable to parameter `targets` with type `list[tuple[str, str]] | None` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.send_message` [bad-argument-type]
+ ERROR tests/test_plugin_xmpp.py:2530:45-50: Argument `list[str]` is not assignable to parameter `targets` with type `list[tuple[str, str]]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter._send_keepalive_async` [bad-argument-type]
+ ERROR tests/test_plugin_xmpp.py:2575:45-50: Argument `list[str]` is not assignable to parameter `targets` with type `list[tuple[str, str]]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter._send_keepalive_async` [bad-argument-type]
+ ERROR tests/test_plugin_xmpp.py:3484:37-42: Argument `list[str]` is not assignable to parameter `targets` with type `list[tuple[str, str]]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter._send_keepalive_async` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:3579:17-47: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:3617:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:3649:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:3849:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:3879:17-44: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
+ ERROR tests/test_plugin_xmpp.py:3947:45-62: Argument `list[str]` is not assignable to parameter `targets` with type `list[tuple[str, str]]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter._send_keepalive_async` [bad-argument-type]
+ ERROR tests/test_plugin_xmpp.py:4366:17-69: Argument `list[str]` is not assignable to parameter `targets` with type `list[tuple[str, str]] | None` in function `apprise.plugins.xmpp.base.NotifyXMPP.__init__` [bad-argument-type]
+ ERROR tests/test_plugin_xmpp.py:4433:17-52: Argument `list[str]` is not assignable to parameter `targets` with type `list[tuple[str, str]] | None` in function `apprise.plugins.xmpp.base.NotifyXMPP.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:4575:17-63: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:4612:21-67: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter._send_keepalive_async` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:4644:17-63: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:4682:21-67: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter._send_keepalive_async` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:4714:17-63: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:4767:17-63: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter.__init__` [bad-argument-type]
- ERROR tests/test_plugin_xmpp.py:4803:21-67: Argument `list[tuple[str, str]]` is not assignable to parameter `targets` with type `list[str]` in function `apprise.plugins.xmpp.adapter.SlixmppAdapter._send_keepalive_async` [bad-argument-type]
pywin32 (https://github.com/mhammond/pywin32)
+ ERROR win32/Demos/getfilever.py:28:5-19: Cannot unpack str into 2 values [bad-unpacking]
|
Primer Diff Classification❌ 1 regression(s) | ✅ 1 improvement(s) | 2 project(s) total | +16, -33 errors 1 regression(s) across pywin32. error kinds:
Detailed analysis❌ Regression (1)pywin32 (+1)
✅ Improvement (1)apprise (+15, -33)
Suggested fixesSummary: The pywin32 regression is a single pyrefly-only bad-unpacking error caused by incomplete type stubs for the win32api C extension (GetFileVersionInfo returns Any/str instead of list[tuple]), triggering the new string-unpacking check; the check itself is working as designed. 1. In
Was this helpful? React with 👍 or 👎 Classification by primer-classifier (2 LLM) |
|
Looks like the problem with tuple handling. |
Summary
Fixes #3352
unpack-length checking rejects string-like unpack sources (str, string literals, LiteralString) with bad-unpacking, which catches for k, v in {"x": 1} because dict iteration yields keys.
Test Plan
update && add test