Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'argument': 0.04; 'arguments': 0.07; 'matches': 0.07; 'check.': 0.09; 'here?': 0.09; 'sentence': 0.09; 'template': 0.11; 'ignore': 0.13; 'language': 0.14; '__len__,': 0.16; 'foo;': 0.16; 'former,': 0.16; 'readable': 0.16; 'sense,': 0.16; 'thoughts?': 0.16; 'wording': 0.16; 'written.': 0.16; 'wrote:': 0.17; '8bit%:3': 0.17; 'typing': 0.17; 'to:name:python-list@python.org': 0.20; 'skip:- 40': 0.21; 'thanks.': 0.21; 'java': 0.21; 'latter': 0.22; 'precise': 0.22; 'programming': 0.23; 'to:2**1': 0.23; 'testing': 0.24; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'looks': 0.26; 'url:wiki': 0.26; 'language.': 0.27; 'reflect': 0.27; 'assert': 0.29; 'url:wikipedia': 0.29; 'date:': 0.29; 'url:mailman': 0.29; 'points': 0.29; 'words': 0.29; 'probably': 0.29; 'class': 0.29; "i'm": 0.29; 'fri,': 0.30; 'function': 0.30; 'sense': 0.31; 'point': 0.31; 'url:python': 0.32; 'url:listinfo': 0.32; 'from:addr:live.com': 0.33; 'to:addr:python-list': 0.33; 'likely': 0.33; 'skip:d 20': 0.34; 'clear': 0.35; 'direction': 0.35; 'false': 0.35; 'nov': 0.35; 'replaced': 0.35; 'pm,': 0.35; 'there': 0.35; 'subject:': 0.36; 'but': 0.36; 'url:org': 0.36; 'limitation': 0.36; 'email addr:python.org': 0.36; 'test': 0.36; 'thank': 0.36; 'two': 0.37; 'passed': 0.37; 'subject:: ': 0.38; 'from:': 0.38; 'easier': 0.38; 'skip:l 20': 0.38; 'some': 0.38; 'sure': 0.38; 'url:en': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'notice': 0.39; 'url:mail': 0.40; 'think': 0.40; 'lost': 0.60; 'skip:u 10': 0.60; 'email name :python-list': 0.62; 'safe': 0.63; 'skip:n 10': 0.63; 'email addr:gmail.com': 0.63; 'more': 0.63; 'believe': 0.69; '+1100': 0.84; 'confusion.': 0.84; 'probably,': 0.84; 'say:': 0.84; 'do:': 0.91; 'hand,': 0.97; 'charset:windows-1251': 0.97 X-Originating-IP: [194.44.213.194] From: Andriy Kornatskyy To: , "python-list@python.org" Subject: RE: duck typing assert Date: Fri, 9 Nov 2012 13:26:36 +0300 Importance: Normal In-Reply-To: References: , <509c412d$0$29980$c3e8da3$5496439d@news.astraweb.com>, , Content-Type: text/plain; charset="windows-1251" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 09 Nov 2012 10:26:36.0755 (UTC) FILETIME=[B2B0CA30:01CDBE64] 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: 83 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352456865 news.xs4all.nl 6845 [2001:888:2000:d::a6]:57898 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33008 Thank you for all comments. > It=A0makes very good sense to say: > > duckmatch(IFoo).compare(Foo) Since we do duck match of IFoo... but there is no `duck match`=2C there is = `duck test`.=A0I believe instead of `compare` is more readable with `equals= `. Than it is more from=A0mathematics - precise answer...=A0that you can no= t guarantee at all in dynamic programming language. So it false to use such= wording to reflect this check. We can only make an assumption that one loo= ks like the other (similar)... with some limitation of cause... understandi= ng what is `duck test`. http://en.wikipedia.org/wiki/Duck_test The intent is to make such language `construct` so it reads as English sent= ence that make sense=2C and not mandatory `pythonic` way (readability count= s=2C java smokes aside). is_similar(Foo).to(IFoo) # <=3D but we lost `duck test` sense here? Words `looks` and `like` are coming from duck test and point also direction= : # 1 looks(Foo).like(IFoo=2C notice=3D['__len__']=2C ignore_funcs=3D['foo']=2C i= gnore_argspec['bar']) English sentence equivalent: if functions in Foo looks like one in IFoo tha= n=2C probably=2C IFoo can be replaced with Foo=3B notice to check __len__= =2C it is safe to ignore function `foo` and arguments passed to `bar`. # 2 looks(Foo=2C notice=3D['__len__']=2C ignore_funcs=3D['foo']=2C ignore_argsp= ec['bar']).like(IFoo) English sentence equivalent:=A0while looking at Foo notice to check `__len_= _`=2C it is safe to ignore function `foo` and=A0arguments passed to `bar`= =2C than probably it like IFoo. I think #1 is easier to understand once it is written. Thoughts? Also construction=A0looks(Foo).like(IFoo) points direction of check. It you= need the two be replaceable you need two asserts: assert looks(Foo).like(IFoo) assert looks(IFoo).like(Foo) Thanks. Andriy Kornatskyy ---------------------------------------- > Date: Fri=2C 9 Nov 2012 17:14:49 +1100 > Subject: Re: duck typing assert > From: rosuav@gmail.com > To: python-list@python.org > > On Fri=2C Nov 9=2C 2012 at 12:00 PM=2C Ian Kelly = wrote: > > looks(Foo).like(IFoo)=2C on the other hand=2C is crystal clear about wh= ich > > argument is which. > > I'm not so sure that it is=2C tbh. If you read it like an English > sentence=2C it's clearly testing whether Foo matches the template in > IFoo=2C but which are you more likely to do: test one class to see if it > satisfies lots of templates=2C or test one template against every class > you meet? I think probably the latter is=2C if not more likely than the > former=2C at least sufficiently plausible as to create confusion. It > makes very good sense to say: > > duckmatch(IFoo).compare(Foo) > > ie with the arguments the other way. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list =