Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #197208

[SOLVED] Struggling to understand Callable type hinting

From Ian Pilcher <arequipeno@gmail.com>
Newsgroups comp.lang.python
Subject [SOLVED] Struggling to understand Callable type hinting
Date 2025-01-18 10:17 -0600
Message-ID <mailman.90.1737217058.2912.python-list@python.org> (permalink)
References <f01d0808-16fb-4b91-a518-a84d6973fee1@gmail.com> <113709c0-0530-47c7-ad8d-8294dd00924f@DancesWithMice.info> <3da391eb-b245-429b-bcc1-3c88ef557241@gmail.com> <11ea559c-26da-4676-8bfc-1e58660d45cd@gmail.com>

Show all headers | View raw


(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
========================================================================

Back to comp.lang.python | Previous | Next | Find similar


Thread

[SOLVED] Struggling to understand Callable type hinting Ian Pilcher <arequipeno@gmail.com> - 2025-01-18 10:17 -0600

csiph-web