• [SOLVED] Struggling to understand Callable type hinting

    From Ian Pilcher@3:633/280.2 to All on Sun Jan 19 03:17:31 2025
    (Note: I have mail delivery disabled for this list and read it through
    GMane, so I am unable to respond with correct threading if I'm not cc'ed directly.)

    On 1/18/25 8:52 AM, Ian Pilcher wrote:
    (And even that wouldn't really be correct, if it worked, because it
    doesn't express the fact that the arguments of the two Callables are the same. I believe that ParamSpecs are supposed to address this, but there doesn't seem to be any way to use a ParamSpec when one or more of the parameter types is known.

    I think that I figured it out.

    __P = typing.ParamSpec('__P')

    @staticmethod
    def _check_eof(
    method: collections.abc.Callable[
    typing.Concatenate[BufferScanner, __P], None
    ]
    ) -> (
    collections.abc.Callable[
    typing.Concatenate[BufferScanner, __P], bool
    ]
    ):
    ...

    Mypy is happy, and it catches me if I try to use the decorator on some-
    thing that isn't a method of BufferScanner (or some other callable that
    takes an instance of BufferScanner as its first positional argument).

    --
    ========================================================================
    If your user interface is intuitive in retrospect ... it isn't intuitive ========================================================================

    --- MBSE BBS v1.0.8.4 (Linux-x86_64)
    * Origin: ---:- FTN<->UseNet Gate -:--- (3:633/280.2@fidonet)