Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypedDict.setdefault gives error when type is a TypeVar #17674

Open
bmerry opened this issue Aug 14, 2024 · 0 comments
Open

TypedDict.setdefault gives error when type is a TypeVar #17674

bmerry opened this issue Aug 14, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@bmerry
Copy link
Contributor

bmerry commented Aug 14, 2024

Bug Report

When a function argument is annotated using a TypeVar with a bound that is a TypedDict, using setdefault on it leads to an error.

To Reproduce

from typing import TypedDict, TypeVar

class TD(TypedDict, total=False):
    foo: int
    bar: bool

_T = TypeVar("_T", bound=TD)

def func(td: _T) -> None:
    td.setdefault("bar", True)

Actual Behavior

testit.py:10: error: Argument 1 to "setdefault" of "TypedDict" has incompatible type "str"; expected "Never"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: mypy 1.11.1 (compiled: yes)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): no config file
  • Python version used: 3.12.3
@bmerry bmerry added the bug mypy got something wrong label Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant