Repository navigation
fix TypeVar with constraints not resolving __getitem__ #3059 - #3358
asukaminato0721 wants to merge 1 commit into
Conversation
|
Diff from mypy_primer, showing the effect of this PR on open source code: core (https://github.com/home-assistant/core)
- ERROR homeassistant/components/bluetooth/match.py:200:54-73: Cannot index into `_T` [bad-index]
- ERROR homeassistant/components/bluetooth/match.py:207:34-58: Cannot index into `_T` [bad-index]
- ERROR homeassistant/components/bluetooth/match.py:211:31-52: Cannot index into `_T` [bad-index]
- ERROR homeassistant/components/bluetooth/match.py:215:36-62: Cannot index into `_T` [bad-index]
- ERROR homeassistant/components/bluetooth/match.py:227:54-73: Cannot index into `_T` [bad-index]
- ERROR homeassistant/components/bluetooth/match.py:233:34-58: Cannot index into `_T` [bad-index]
- ERROR homeassistant/components/bluetooth/match.py:237:31-52: Cannot index into `_T` [bad-index]
- ERROR homeassistant/components/bluetooth/match.py:241:36-62: Cannot index into `_T` [bad-index]
- ERROR homeassistant/data_entry_flow.py:327:48-329:14: Cannot index into `_FlowResultT` [bad-index]
- ERROR homeassistant/data_entry_flow.py:333:29-43: Cannot index into `_FlowResultT` [bad-index]
- ERROR homeassistant/data_entry_flow.py:376:12-28: Cannot index into `_FlowResultT` [bad-index]
- ERROR homeassistant/data_entry_flow.py:382:23-42: Cannot index into `_FlowResultT` [bad-index]
- ERROR homeassistant/data_entry_flow.py:385:12-28: Cannot index into `_FlowResultT` [bad-index]
- ERROR homeassistant/data_entry_flow.py:389:69-391:14: Cannot index into `_FlowResultT` [bad-index]
- ERROR homeassistant/data_entry_flow.py:399:69-401:14: Cannot index into `_FlowResultT` [bad-index]
- ERROR homeassistant/data_entry_flow.py:415:16-35: Cannot index into `_FlowResultT` [bad-index]
- ERROR homeassistant/data_entry_flow.py:416:17-31: Cannot index into `_FlowResultT` [bad-index]
- ERROR homeassistant/data_entry_flow.py:418:21-48: Cannot index into `_FlowResultT` [bad-index]
- ERROR homeassistant/data_entry_flow.py:419:24-60: Cannot index into `_FlowResultT` [bad-index]
- ERROR homeassistant/data_entry_flow.py:494:16-30: Cannot index into `_FlowResultT` [bad-index]
- ERROR homeassistant/data_entry_flow.py:502:27-41: Cannot index into `_FlowResultT` [bad-index]
- ERROR homeassistant/data_entry_flow.py:536:54-71: Cannot index into `_FlowResultT` [bad-index]
- ERROR homeassistant/data_entry_flow.py:553:12-26: Cannot index into `_FlowResultT` [bad-index]
- ERROR homeassistant/helpers/collection.py:269:21-41: Cannot index into `_StoreT` [bad-index]
- ERROR homeassistant/helpers/collection.py:277:29-49: Cannot index into `_StoreT` [bad-index]
- ERROR homeassistant/helpers/event.py:351:45-68: Cannot index into `_StateEventDataT` [bad-index]
- ERROR homeassistant/helpers/event.py:359:17-40: Cannot index into `_StateEventDataT` [bad-index]
- ERROR homeassistant/helpers/event.py:371:12-35: Cannot index into `_StateEventDataT` [bad-index]
|
Primer Diff Classification✅ 1 improvement(s) | 1 project(s) total | -28 errors 1 improvement(s) across core.
Detailed analysis✅ Improvement (1)core (-28)
Was this helpful? React with 👍 or 👎 Classification by primer-classifier (1 LLM) |
There was a problem hiding this comment.
Pull request overview
Fixes a false-positive when subscripting a constrained TypeVar whose constraints are TypedDict types (issue #3059) by teaching subscript inference to resolve indexing against the TypeVar’s bound/constraints rather than attempting __getitem__ directly on the TypeVar.
Changes:
- Update
subscript_infer_for_typeto handle restrictedTypeVars by delegating subscript inference to the TypeVar’s bound or to the union of its constraints. - Add a regression test covering constrained
TypeVar+TypedDictindexing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
pyrefly/lib/alt/expr.rs |
Adjusts subscript inference for restricted TypeVars to use bound/constraints so TypedDict subscripting resolves correctly. |
pyrefly/lib/test/typed_dict.rs |
Adds a regression test reproducing #3059 and asserting the inferred type for device[NAME]. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| assert_type(name, str) | ||
| self.by_name.setdefault(name, []).append(device) | ||
|
|
||
| def lookup(self, device: T) -> str: |
|
@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D107101498. |
rchen152
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
@yangdanny97 merged this pull request in 4b40b3c. |
Summary
Fixes #3059
restricted TypeVar subscripting uses the bound or constraint types directly, which reuses the existing precise TypedDict indexing path instead of falling back to
object.__getitem__.Test Plan
add test