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


Groups > comp.lang.python > #197200

Re: Struggling to understand Callable type hinting

From dn <PythonList@DancesWithMice.info>
Newsgroups comp.lang.python
Subject Re: Struggling to understand Callable type hinting
Date 2025-01-18 14:26 +1300
Organization DWM
Message-ID <mailman.88.1737163576.2912.python-list@python.org> (permalink)
References <f01d0808-16fb-4b91-a518-a84d6973fee1@gmail.com> <113709c0-0530-47c7-ad8d-8294dd00924f@DancesWithMice.info>

Show all headers | View raw


On 18/01/25 12:33, Ian Pilcher via Python-list wrote:
> I am making my first attempt to use type hinting in a new project, and
> I'm quickly hitting areas that I'm having trouble understanding.  One of
> them is how to write type hints for a method decorator.
> 
> Here is an example that illustrates my confusion.  (Sorry for the
> length.)
> 
> 
> import collections.abc
> 
> class BufferScanner(object):
> 
...

>      @staticmethod
>      def _check_eof(method: collections.abc.Callable -> (
>          collections.abc.Callable
>      ):
...
> 
> I cannot figure out how to correctly specify the Callable argument and
> return type for _check_eof().  As indicated by the name, method should
> be a method (of the BufferScanner class), so its first positional
> argument should always be an instance of BufferScanner, but it could
> have any combination of positional and/or keyword arguments after that.

Is it a typing problem?
The def is not syntactically-correct (parentheses).
What happens once corrected?

Also, which tool is 'complaining', and what does it have to say?

General comment: as far as type-hints go, rather than trying to learn 
how to deal with complex situations, it might be better to ease-in 
gradually - add the easy stuff now, and come back to deal with the rest 
later (otherwise the typing 'tail' is wagging the coding 'dog'!)

-- 
Regards,
=dn

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


Thread

Re: Struggling to understand Callable type hinting dn <PythonList@DancesWithMice.info> - 2025-01-18 14:26 +1300

csiph-web