pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

[mypy parity] We should look at narrowing on dict (and typed dict) .get

Open stroxler opened this issue 8 months ago • 1 comments

Describe the Bug

We ran into an issue trying to migrate someone where they wanted to narrow the .get(<key>) access on a dictionary (where the key was a literal string) from Any | None to Any

This would be a good thing to support, both for migration and general usability

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

stroxler avatar May 17 '25 20:05 stroxler

Example:

x: dict[str, int] = {}
if x.get("y") is not None:
    assert_type(x.get("y"), int)

yangdanny97 avatar May 18 '25 02:05 yangdanny97

This issue has someone assigned, but has not had recent activity for more than 2 weeks.

If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.

Thank you for your contributions!

github-actions[bot] avatar Jul 06 '25 00:07 github-actions[bot]

This issue has someone assigned, but has not had recent activity for more than 2 weeks.

If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.

Thank you for your contributions!

github-actions[bot] avatar Aug 29 '25 00:08 github-actions[bot]