Skip to content

Special-case .pop() on TypedDict #18296

Open
@Lancetnik

Description

@Lancetnik

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) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions