Special-case .pop() on TypedDict
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Mypy doesn't respect TypedDict object changes. As an example, the following snippet
from typing import TypedDict
class A(TypedDict, total=False):
a: str
def func(a: str) -> None:
pass
data: A = {"a": "a"}
a = data.pop("a", "")
func(a, **data)
Raises the error:
error: "func" gets multiple values for keyword argument "a" [misc]
Formally, it is correctly, but it will be nice if mypy respects object keys changes. Especially in Unpack case:
from typing import Unpack, TypedDict
class A(TypedDict, total=False):
a: str
def func(a: str) -> None:
pass
def func2(**data: Unpack[A]) -> None:
a = data.pop("a", "")
func(a, **data)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two TypedDict examples with mypy, focusing on .pop() followed by keyword unpacking and Unpack handling. Trace the existing TypedDict key-tracking and duplicate-key diagnostic paths; done means valid code using the removed key no longer reports a duplicate keyword argument while invalid cases remain diagnosed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100