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

(Partial) keyword argument forwarding #1524

Open
srittau opened this issue Dec 6, 2023 · 1 comment
Open

(Partial) keyword argument forwarding #1524

srittau opened this issue Dec 6, 2023 · 1 comment
Labels
topic: feature Discussions about new features for Python's type annotations

Comments

@srittau
Copy link
Collaborator

srittau commented Dec 6, 2023

Split from #1000.


I have a similar use case with Ariadne middleware functions, but with kwargs. In Ariadne, a "resolver" function takes two positional arguments and a varying number of keyword arguments that depend on the API the resolver implements. As the name implies, a middleware function sits between Ariadne and the resolver function and forwards arguments.

Ideally, I would like to type a middleware function as follows:

_P = ParamSpec("_P")
_R = TypeVar("_R")
_T = TypeVar("_T")

def foo_middleware(
    resolver: Callable[Concatenate[_T, GraphQLResolveInfo, _P], _R],
    obj: _T,
    info: GraphQLResolveInfo,
    /,
    **kwargs: _P.kwargs,
) -> _R:
    ...
    return resolver(obj, info, **kwargs)

But currently this isn't possible, because _P.args is "missing".

@srittau srittau added the topic: feature Discussions about new features for Python's type annotations label Dec 6, 2023
@Daverball
Copy link
Contributor

My understanding of PEP612 always was that the "pos-args-only" and "kwargs-only" case (and any other arbitrary restriction) would be supported in the future through upper bounds, the main limiting factor of this, is that we don't have a complete way to manually bind a param spec yet (without using another callable). We've relied on callback protocols as a workaround for the Callable syntax not being expressive enough to capture all the possible types of arguments.

PEP646 let us cover one very important use-case "pos-args-only", but it also doesn't specify upper bounds yet, so we can't cover all the possible uses of *args either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: feature Discussions about new features for Python's type annotations
Projects
None yet
Development

No branches or pull requests

2 participants