[pyrefly] Contextualize dict subscript literals for Any - #4391
Conversation
|
This pull request has been imported. If you are a Meta employee, you can view this in D114458708. (Because this pull request was imported automatically, there will not be any future comments.) |
|
Heads up rather than having this show up unannounced — I opened #4409 with a more general take on the same bug. You got here first, and I'd rather flag it than surprise you. Same idea, but keyed on whether the placeholder can escape rather than on the target's shape, which turned out to matter more than I expected. Measured, both patches applied to the same base and run on the same inputs:
The key-type condition in the qname match is what narrows yours: the key has nothing to do with whether the value is Digging further also turned up a second root cause behind the same diagnostic: checking against Genuinely happy to fold this into your PR instead of landing it separately if you'd prefer — the analysis is the part I care about, not whose branch it goes in on. |
Fixes #4301
A dict literal assigned through an explicitly annotated
dict[str, Any]subscript now receives a soft value hint, avoiding a spuriousimplicit-any-empty-containerdiagnostic. Unannotated and narrow dictionary targets retain their existing diagnostics and inference behavior.Validation:
cargo test -p pyrefly test::inference::test_implicit_anycargo test -p pyrefly test::dictpython3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschemaThe local
.scratchplanning files are intentionally not part of this PR.