Skip to content

Question: Partial callable signature #6077

Closed

Description

@mehdigmira

Hello,

When using decorators, we often know that the function that will be decorated should take param x and y, but we don't care about the rest of the parameters. Is there currently a way to do this ?
Something like Callable[[str,...], Any] would be perfect. It would work for f(x: str) but also for f(x: str, y: int) and f(x: str, *args, **kwargs)

Activity

  1. JelleZijlstra commented on Dec 18, 2018

    @JelleZijlstra
    Member
  2. mehdigmira commented on Dec 18, 2018

    @mehdigmira
    Author

    I was not able to make it work with callable protocols either

    from typing import Any
    
    from typing_extensions import Protocol
    
    
    class DecoratedF(Protocol):
        def __call__(self, a: str, *args: Any) -> None: ...
    
    
    def g(f: DecoratedF): ...
    
    
    @g
    def f(a: str, b: str) -> None: ...

    Am I doing smth wrong ?

  3. ilevkivskyi commented on Dec 18, 2018

    @ilevkivskyi
    Member

    This is actually very similar to #5876 (see also a decorator example there). Which is opposite to the idea of callback protocols in some sense. Callback protocols allow to express signatures that are impossible to express using Callable syntax. However, there is something that can be expressed using Callable that can't be expressed as a signature, for example Callable[..., int] (with literal ...).

    Potentially we can just also allow special meaning for *args: Any, **kwds: Any at the end of a signature to mean "I don't care" instead of "Should allow all possible calls".

  4. JukkaL commented on Jan 29, 2020

    @JukkaL
    Collaborator

    We don't want to support a non-standard extension to the callable syntax, so proposed changes should go through the typing issue tracker or typing-sig@.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions