Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created May 24, 2025 11:19
Show Gist options
  • Save mypy-play/4c9ca727dbc78127c4934f43edfdcc00 to your computer and use it in GitHub Desktop.
Save mypy-play/4c9ca727dbc78127c4934f43edfdcc00 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from typing import Callable, Generic, TypeVarTuple, Unpack
# side note: something like this syntax seems unsupported
# class Class[*Ts=Unpack[tuple[()]]]]:
Ts = TypeVarTuple("Ts", default=Unpack[tuple[()]])
class Class(Generic[*Ts]):
def foo(self, x: Callable[[*Ts], None]) -> None: ...
def x_no_args() -> None: ...
# works as expected
Class().foo(x_no_args)
# fails
obj: Class = Class()
obj.foo(x_no_args)
# also fails
class Other:
obj: Class
Other().obj.foo(x_no_args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment