Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created February 12, 2026 15:06
Show Gist options
  • Select an option

  • Save mypy-play/8f3bc3a64783a873c24dcc51b59deab1 to your computer and use it in GitHub Desktop.

Select an option

Save mypy-play/8f3bc3a64783a873c24dcc51b59deab1 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from typing import Callable, TypeVar
_K = TypeVar("_K")
_V = TypeVar("_V")
class Foo:
pass
class Util:
@staticmethod
def apply(i: str, g: Callable[[str], _K]) -> _K:
return g(i)
@staticmethod
def constructor(_: dict[_K, _V]) -> Foo:
return Foo()
def proof_of_concept(
f: Callable[[int], str],
) -> None:
Util.constructor(
{
f("foo"): f("not_int")
}
| Util.apply(
"", lambda _: {}
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment