Skip to content

Missing type inference through upper bound creates error in Unpack #21051

@JohannesWeinbrecht

Description

@JohannesWeinbrecht

Bug Report

Missing type inference through upper bound of generic type variable leads to error on Unpack in kwargs type hint.

To Reproduce

from typing import TypedDict, Unpack, Any
from abc import abstractmethod

class SomeGeneralOptions(TypedDict):
    some_option1: bool

class GenericParentClass[SomeOptions: SomeGeneralOptions]:

    def some_wrapper_method(self, val1, val2, **kwargs: Unpack[SomeOptions]) -> Any:
        return True

MyPy Play Link

Expected Behavior

Please correct me if I am wrong, but I think there should be no error due to the upper bound, which ensures that the typevariable is a TypedDict.

Actual Behavior

exampleSimple.py:9: error: Unpack item in ** argument must be a TypedDict  [misc]

Your Environment

  • Mypy version used: 1.19.1
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used:
    • MyPy Playground: 3.14
    • Local: 3.13.7

As I am only a student and not a professional developer in any way, it would be nice to receive feedback if this actually a MyPy bug, or if I just lack in understanding.

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