Skip to content

Instantly share code, notes, and snippets.

@thatfunkymunki
Last active June 3, 2026 23:23
Show Gist options
  • Select an option

  • Save thatfunkymunki/c0c8a57d60f0f02217b918ef6a377189 to your computer and use it in GitHub Desktop.

Select an option

Save thatfunkymunki/c0c8a57d60f0f02217b918ef6a377189 to your computer and use it in GitHub Desktop.
pyrefly vs mypy repro
from typing import Protocol, Generic, Callable, Iterator, cast
from typing_extensions import ParamSpec
P = ParamSpec("P")
class FooResult:
changed: bool
class FooProtocol(Generic[P], Protocol):
def __call__(
self,
_bar: bool = False,
baz: str | None = None,
*args: P.args,
**kwargs: P.kwargs,
) -> FooResult: ...
def make_foo(func: Callable[P, Iterator[str]]) -> FooProtocol[P]:
def wrapper(*args: P.args, **kwargs: P.kwargs) -> FooResult:
return FooResult()
return cast(FooProtocol[P], wrapper)
def _foo_impl(biz: str, baf: bool = True) -> Iterator[str]:
yield "test"
foo = make_foo(_foo_impl)
# These should all be valid:
foo(biz="aaa")
foo(biz="bbb", baf=True)
foo(biz="ccc", _bar=True)
foo(biz="ddd", baf=True, _bar=True, baz="abcdef")
# This should be an error:
foo(nonexistent_param=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment