Deutsch English Français Italiano |
<mailman.88.1737163576.2912.python-list@python.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail From: dn <PythonList@DancesWithMice.info> Newsgroups: comp.lang.python Subject: Re: Struggling to understand Callable type hinting Date: Sat, 18 Jan 2025 14:26:02 +1300 Organization: DWM Lines: 42 Message-ID: <mailman.88.1737163576.2912.python-list@python.org> References: <f01d0808-16fb-4b91-a518-a84d6973fee1@gmail.com> <113709c0-0530-47c7-ad8d-8294dd00924f@DancesWithMice.info> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de Rz6mBNQqaJu9u4DA3VRtEg9gbWHXkDNWhwq/T/sMVdCQ== Cancel-Lock: sha1:guaoMSWY7wwy9h/G9lrkwXT984c= sha256:8GCBo3kAPPj0/Hi0Ib8Ewu65Wo2T+VnRD39IT9GV7OE= Return-Path: <PythonList@DancesWithMice.info> X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org Authentication-Results: mail.python.org; dkim=pass reason="2048-bit key; unprotected key" header.d=danceswithmice.info header.i=@danceswithmice.info header.b=l2+gA6Yx; dkim-adsp=pass; dkim-atps=neutral X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'project,': 0.03; 'skip:@ 10': 0.03; 'argument': 0.04; 'def': 0.04; 'comment:': 0.05; 'hitting': 0.07; '=dn': 0.09; 'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist': 0.09; 'problem?': 0.09; 'coding': 0.13; 'import': 0.15; 'that.': 0.15; 'arguments': 0.16; 'gradually': 0.16; 'hints': 0.16; 'instance': 0.16; 'message- id:@DancesWithMice.info': 0.16; 'received:51.254': 0.16; 'received:51.254.211': 0.16; 'received:51.254.211.219': 0.16; 'received:cloud': 0.16; 'received:rangi.cloud': 0.16; 'specify': 0.16; 'subject:hinting': 0.16; 'typing': 0.16; 'wrote:': 0.16; 'figure': 0.19; 'to:addr:python-list': 0.20; 'skip:_ 10': 0.22; 'stuff': 0.25; 'cannot': 0.25; 'header:User-Agent:1': 0.30; 'attempt': 0.31; 'keyword': 0.32; 'python-list': 0.32; 'header:Organization:1': 0.32; 'but': 0.32; "i'm": 0.33; 'header :In-Reply-To:1': 0.34; 'trying': 0.35; 'complex': 0.35; 'also,': 0.36; "skip:' 10": 0.37; 'could': 0.37; 'class': 0.37; 'example': 0.37; 'received:192.168': 0.37; 'use': 0.39; 'rest': 0.39; 'learn': 0.40; 'should': 0.40; 'method': 0.61; 'skip:\xc2 10': 0.62; 'come': 0.62; 'here': 0.63; 'once': 0.63; 'skip:b 20': 0.63; 'skip:b 10': 0.63; 'received:51': 0.64; 'tool': 0.65; 'back': 0.66; 'now,': 0.67; 'areas': 0.67; 'deal': 0.73; 'easy': 0.74; 'name,': 0.75; '8bit%:100': 0.76; '....': 0.76; 'combination': 0.76; 'quickly': 0.80; 'indicated': 0.81; 'happens': 0.84; 'go,': 0.84; 'situations,': 0.84; 'subject:type': 0.93 DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud 4C7485FFD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info; s=staff; t=1737163568; bh=VvUjOGQHb1ERgHxERwVn0Vo6ZIau9ntsyfNYWsUVsVI=; h=Date:From:Subject:To:References:In-Reply-To:From; b=l2+gA6YxKEwBcbDgJH22YZqlPjjpmjoC75CyKNvRxknEOMUvcSAJEWwTltG247nlJ NtdPyPaNVwwaqmF82wKjQKMVoHQvQbnuBtaZszUm2kF92bAzRoTsJl6oYgpjlWFtUU +6mO7Gak3cEVZa91stnnM+Hqg1QHvQmSGjqf95hnWkNhlu7GC0mxieeVaaloVGWqU8 yKFHat+5fOCNmdmt4LetHMgFW5MNFBLxgwDyWEMRjammapASSqPZ3LOmJZUc6z/0TB vHqYEbmrUYqIhf/YbrrREZjgznzU9Dq2BJk1Ng8zxisZrylauWzggPY+2bO9UWdC1h q7S9/lAfSa+qQ== User-Agent: Mozilla Thunderbird Content-Language: en-US In-Reply-To: <f01d0808-16fb-4b91-a518-a84d6973fee1@gmail.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.39 Precedence: list List-Id: General discussion list for the Python programming language <python-list.python.org> List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> List-Archive: <https://mail.python.org/pipermail/python-list/> List-Post: <mailto:python-list@python.org> List-Help: <mailto:python-list-request@python.org?subject=help> List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> X-Mailman-Original-Message-ID: <113709c0-0530-47c7-ad8d-8294dd00924f@DancesWithMice.info> X-Mailman-Original-References: <f01d0808-16fb-4b91-a518-a84d6973fee1@gmail.com> Bytes: 5694 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