pyrefly
pyrefly copied to clipboard
Does not allow popping from a TypedDict
Describe the Bug
For this program:
from typing import ReadOnly, TypedDict, NotRequired
class TD(TypedDict):
x: NotRequired[int]
def f(td: TD):
td.pop("x")
Pyrefly (playground as of just now) reports:
ERROR 7:12-15: Argument `Literal['x']` is not assignable to parameter `k` with type `Never` in function `typing._TypedDict.pop` [[bad-argument-type](https://pyrefly.org/en/docs/error-kinds/#bad-argument-type)]
Other type checkers allow this, correctly in my view. I just reported bugs to mypy (python/mypy#19130) and pyright (microsoft/pyright#10489) where they fail to reject .pop when combined with ReadOnly, so I was curious what pyrefly did. It passes that test case but also rejects .pop in all other cases, which is incorrect.
Sandbox Link
https://pyrefly.org/sandbox/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoBKApgIYAmA8igDZwA0UAKokWQCJIDGMDAcmDGIBHAK5IQrAFCTO1EgGd5TNgApmCVh24BKAFySohqAA9dUfoKKjxrANqoYAXQNHJZIsCjAVMMmcZsei6GvgB0OAgqAETGUdpAA
(Only applicable for extension issues) IDE Information
No response
Thanks for reporting! We do not have any special handling for methods on TypedDicts right now, but we'll keep ReadOnly semantics in mind when we do get around to supporting it.
fixed