Skip to content

name-defined error lets Mypy forget TypedDict was wrapped in Unpack #17225

Closed
@tyralla

Description

@tyralla
from typing import overload, TypedDict, Unpack

class TD(TypedDict, total=False):
    x: float
    y: str

@overload
def f(*, x: float) -> None: ...
@overload
def f(*, y: str) -> None: ...
def f(**kwargs: Unpack[TD]) -> None:  # error: Overloaded function implementation does not accept all possible arguments of signature 1 [misc]
                                      # error: Overloaded function implementation does not accept all possible arguments of signature 1 [misc]
    y  # error: Name "y" is not defined

class A:
    def f(self, *, x: float) -> None: ...
class B(A):
    def f(self, **kwargs: Unpack[TD]) -> None:  # error: Argument 1 of "f" is incompatible with supertype "A"; supertype defines the argument type as "float"  [override]
        y  # type: ignore[name-defined]
reveal_type(B.f)  # note: Revealed type is "def (self: temp.B, **kwargs: TypedDict('temp.TD', {'x'?: builtins.float, 'y'?: builtins.str}))"
B().f(x=1.0)  # error: Argument "x" to "f" of "B" has incompatible type "float"; expected "TD"  [arg-type]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions