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

Allow TypeVarTuple as type argument for subclasses of generic TypedDict #16975

Open
erikkemperman opened this issue Mar 1, 2024 · 1 comment · May be fixed by #16977
Open

Allow TypeVarTuple as type argument for subclasses of generic TypedDict #16975

erikkemperman opened this issue Mar 1, 2024 · 1 comment · May be fixed by #16977
Labels
bug mypy got something wrong topic-pep-646 PEP 646 (TypeVarTuple, Unpack) topic-typed-dict

Comments

@erikkemperman
Copy link
Contributor

erikkemperman commented Mar 1, 2024

Bug Report

I have a TypedDict class which has TypeVarTuple type argument(s), and that works as I would expect. However, when I try to make a class derived from that base class, I get unexpected errors from mypy. Different errors, actually, depending on whether I use Unpack or the new "star" unpacking syntax.

This all ought to work, though, right?

To Reproduce

# typeddict_typevartuple_310.py

from collections.abc import Callable
from typing import Generic, Tuple, TypedDict, TypeVar
from typing_extensions import TypeVarTuple, Unpack

ATs = TypeVarTuple('ATs')
RT = TypeVar('RT')


class BaseDict(TypedDict, Generic[Unpack[ATs], RT]):
    callback: Callable[[Unpack[ATs]], RT]
    arguments: Tuple[Unpack[ATs]]


class DerivedDict(BaseDict[Unpack[ATs], RT]):  # E: Unpack is only valid in a variadic position
    returned: RT
# typeddict_typevartuple_311.py

from collections.abc import Callable
from typing import Generic, TypedDict, TypeVar, TypeVarTuple

ATs = TypeVarTuple('ATs')
RT = TypeVar('RT')


class BaseDict(TypedDict, Generic[*ATs, RT]):
    callback: Callable[[*ATs], RT]
    arguments: tuple[*ATs]


class DerivedDict(BaseDict[*ATs, RT]):  # E: Invalid TypedDict type argument
    returned: RT

Expected Behavior

I would have expected mypy to accept both these versions as correct...

Actual Behavior

... But it fails both of them, with distinct messages (see inline comments).

Your Environment

  • Mypy version used: mypy 1.10.0+dev.3c87af272cbf7c49699b7508c7f51365da139c05 (compiled: no)
  • Mypy command-line flags: n/a
  • Mypy configuration options from mypy.ini (and other config files): n/a
  • Python version used: 3.10 and 3.11
@erikkemperman erikkemperman added the bug mypy got something wrong label Mar 1, 2024
@erikkemperman
Copy link
Contributor Author

By the way, would it be reasonable to expect this to work with ParamSpec too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-pep-646 PEP 646 (TypeVarTuple, Unpack) topic-typed-dict
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants