[SOLVED] Struggling to understand Callable type hinting

Liste des GroupesRevenir à cl python 
Sujet : [SOLVED] Struggling to understand Callable type hinting
De : arequipeno (at) *nospam* gmail.com (Ian Pilcher)
Groupes : comp.lang.python
Date : 18. Jan 2025, 17:17:31
Autres entêtes
Message-ID : <mailman.90.1737217058.2912.python-list@python.org>
References : 1 2 3 4
User-Agent : Mozilla Thunderbird
(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
========================================================================

Date Sujet#  Auteur
18 Jan 25 o [SOLVED] Struggling to understand Callable type hinting1Ian Pilcher

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal