[Python] Type-hinting Callable with positional/keyword only arguments without typing.Protocol

Discussão em 'Python' iniciado por Stack, Junho 24, 2025.

  1. Stack

    Stack Membro Participativo

    I'm wondering if it is possible to type-hint a Callable with positional/keyword only argument without the use of typing.Protocol

    For example in this snippet how would i type-hint x correctly:

    def add(arg: int, /, *, other: str) -> str:
    return f"{arg}{other}"

    x: Callable[[int, str], str] = add
    # `(arg: int, /, *, other: str) -> str` is not assignable to `(int, str) -> str`

    Continue reading...

Compartilhe esta Página