Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!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.047 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'suppose': 0.07; 'unrecognized': 0.07; 'python': 0.09; '"class"': 0.09; 'sat,': 0.15; '(assuming': 0.16; '[1].': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.17; 'received:209.85.214.174': 0.21; 'header:In-Reply-To:1': 0.25; '[1]': 0.27; 'am,': 0.27; 'checking': 0.27; 'message- id:@mail.gmail.com': 0.27; 'fine': 0.28; 'post': 0.28; 'assert': 0.29; 'normally': 0.30; 'expect': 0.31; 'generally': 0.32; 'switch': 0.32; "who's": 0.32; 'problem': 0.33; 'to:addr:python- list': 0.33; 'that,': 0.34; 'received:google.com': 0.34; 'minimum': 0.34; 'nov': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'unable': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'save': 0.61; "you'll": 0.62; '(that': 0.62; 'between': 0.63; 'legal': 0.65; 'hassle.': 0.84; 'offers.': 0.84; 'only:': 0.84; 'openings,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=V9lMERf9ndfQ+RpnUPCGRvfNCXtsweSEEHFWOExuM1g=; b=L8Sbv7tjwog3jNeJVERr+OJrefbV/nwgRc2ZrA8kXt27WFB4Rwj7NYQy6J6ERJiz2Y mUMsdula1IlSdapfogxi6H+vza/Mf3baUsHj5JuFOk0lb16sZr0JUjdhPyZEkoIzGYM3 gbjmJW90rGI0cSjMTWSatEvBkWC+MdWT2DwM5EeSRZWonch33Zw2FTC4RN/fI8sIl7Sj FWQSEnLEWJiIQZa38cll+e8TtAMVCyz+voWgX6cVOneFm8xufqrD5whnjwAS9XRh+tgx 4hmW+om27PjG8kJUFskrhqO/GdlK74Ubesn2tT6h1MUy+zQ3d8jh10aCNZzR+sNpJaGy yiRQ== MIME-Version: 1.0 In-Reply-To: References: <509c412d$0$29980$c3e8da3$5496439d@news.astraweb.com> <509d06e7$0$29980$c3e8da3$5496439d@news.astraweb.com> Date: Sat, 10 Nov 2012 01:15:36 +1100 Subject: Re: duck typing assert From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352470546 news.xs4all.nl 6979 [2001:888:2000:d::a6]:55581 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33027 On Sat, Nov 10, 2012 at 1:01 AM, Andriy Kornatskyy wrote: > > 1. In looks-like we check features of Foo (that may be superset) of what IFoo offers. > > assert looks(Foo).like(IFoo) > > 2. We can check if Foo is limited to IFoo only: > > assert looks(IFoo).like(Foo) > > So it valid to have both asserts. You'll almost never need #2, but since there's no difference between a "class" and an "interface", it's perfectly legal to switch them around. But I would generally expect that unrecognized methods are never a problem (assuming they don't collide with anything) - that, as in Steven's example, it's fine to have an actor who can sing when you don't need her to. When you post job openings, you don't normally ask for someone with "5+ years Python experience and unable to program in REXX" [1]. You're checking for a minimum set of requirements. [1] Though I suppose you might ask for someone who's unable to program in Pascal. Might save you some hassle. ChrisA