Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.041 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'subject:Python': 0.06; '22,': 0.09; 'any)': 0.09; 'def': 0.12; 'jan': 0.12; 'pythonic': 0.16; 'wrote:': 0.18; 'any,': 0.19; 'basically': 0.19; 'thu,': 0.19; '>>>': 0.22; 'either.': 0.24; 'sort': 0.25; 'header:In- Reply-To:1': 0.27; 'chris': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'that.': 0.31; 'received:209.85.212': 0.32; 'cases': 0.33; 'could': 0.34; 'received:209.85': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'functions.': 0.36; 'two': 0.37; 'received:209': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'ian': 0.60; 'full': 0.61; 'providing': 0.61; 'different': 0.65; 'subject:! ': 0.74; '2015': 0.84; 'proposal.': 0.84 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=WDepKS2JwJwJQCUfP2F4EFHZzR/kCt1I6WXfBMHW19c=; b=M1xoHDKUtWUOmivj9N3x1e6K+bT5B6tou2O3d1XWCOQu1DFGEE+yVrWvh37GV55QKZ io7MSpfEZiR/6XzisChqD9/IjpGc+3kKdkz3vRS1nVySNRIeKzazbhbCNAwWfVG7MWPD IbAPtBkoC9GnwK2l2TfJeFa1UUGyuhnO1Nu50zWZAriB78bPHzqGozlVbVpGVsOaO6CE SRhD4iykcME1F5vFWQvIMspjdrR0fEWhmb9m9I/C9YDAoOQhSFzpJRqU772hlWPrmtDq e4CMvZjNdccs9RYpaBs7maF9k/6st0Ant9iinqGrU9/4xACf1S2azLGo0R7XxW92hmid zAAA== X-Gm-Message-State: ALoCoQnQ7R/ElKjRYM8XJq01oUYOcSWv8VPUnB2sqKbF2jlXnMJWOlk4cbo7ZllGUP/mR0uLi5MK X-Received: by 10.194.201.137 with SMTP id ka9mr7859862wjc.66.1421965667323; Thu, 22 Jan 2015 14:27:47 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: <54c07d04$0$13012$c3e8da3$5496439d@news.astraweb.com> From: Chris Kaynor Date: Thu, 22 Jan 2015 14:27:26 -0800 Subject: Re: Python is DOOMED! Again! To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1421965668 news.xs4all.nl 2964 [2001:888:2000:d::a6]:41496 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:84284 On Thu, Jan 22, 2015 at 2:12 PM, Ian Kelly wrote: >>> def adder(a,b): return a+b >>> >>> This is one of the pythonic idioms that help with polymorphic functions. Is >>> there a proposal for providing hinting for these? >> >> You can use TypeVar for that. >> >> T = TypeVar('T') >> >> def adder(a: T, b: T) -> T: >> return a + b >> >> I'm not thrilled about having to actually declare T in this sort of >> situation, but I don't have a better proposal. > > Hmm, but also that hinting doesn't cover cases like adder(12, 37.5) > where two different types can be passed, and the return type could be > either. I think for full generality you would just have to forgo > hinting on this function. Or use Any, which is basically the same thing: def adder(a: Any, b: Any) -> Any: return a + b Chris