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


Groups > comp.lang.python > #32989

Re: duck typing assert

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; 'argument': 0.04; 'arguments': 0.07; 'method,': 0.07; 'speakers,': 0.09; 'typed': 0.09; 'language,': 0.11; 'interfaces': 0.15; 'java,': 0.15; 'naming': 0.16; 'principal.': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'typing': 0.17; 'trying': 0.21; 'programming': 0.23; 'class.': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.25; 'looks': 0.26; 'order.': 0.27; 'convention': 0.27; 'strongly': 0.27; 'message-id:@mail.gmail.com': 0.27; 'assert': 0.29; "d'aprano": 0.29; 'optional': 0.29; 'steven': 0.29; 'class': 0.29; 'function': 0.30; 'could': 0.32; 'to:addr:python-list': 0.33; 'languages': 0.33; 'received:google.com': 0.34; 'clear': 0.35; 'nov': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'test': 0.36; 'does': 0.37; 'two': 0.37; 'being': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'skip:l 20': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'takes': 0.39; 'header:Received:5': 0.40; 'easy': 0.60; 'more': 0.63; 'offer': 0.65; 'lack': 0.71; 'to:name:python': 0.84; 'hand,': 0.97
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=Ufkoqf71Ekxq9x5j0D5RI7YY/gM5T8f9JuQ1UmUKlJU=; b=Bgunx8u+/OME27h4URuTyMvQ9nUIcrAPteUx6iiJtcGcFRbPrHJIWa/mJnc5c04T95 IWugeiP6f8MJz/a6Ypdkj616UkYaKG4qIwNhd2v7nGSmeamaGArVP6maThF68x9FEs/0 +P+bxzSAWb/i34ZsxtAjd7/BEY4ROQPyLQlKX+58Z2vj28xnaswpKwsshbN2yb4iVwfM dw5SdScQGrXxdGITINEw7gBB+xu4YROJWKsVlFBqV90sjWwDmgt3oV46HRNd+GSEXwn1 s51NZe5NGLmndT+OhqmmT9gqeIBPI7bOrNh+PCKanFiaqeJHNlOFL+tqschwQ7pPXjRz oT2Q==
MIME-Version 1.0
In-Reply-To <509c412d$0$29980$c3e8da3$5496439d@news.astraweb.com>
References <mailman.3455.1352396166.27098.python-list@python.org> <509c412d$0$29980$c3e8da3$5496439d@news.astraweb.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Thu, 8 Nov 2012 18:00:58 -0700
Subject Re: duck typing assert
To Python <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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3470.1352422891.27098.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1352422891 news.xs4all.nl 6854 [2001:888:2000:d::a6]:35544
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:32989

Show key headers only | View raw


On Thu, Nov 8, 2012 at 4:33 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> On Thu, 08 Nov 2012 20:34:58 +0300, Andriy Kornatskyy wrote:
>
>> People who come from strongly typed languages that offer interfaces
>> often are confused by lack of one in Python. Python, being dynamic
>> typing programming language, follows duck typing principal. It can as
>> simple as this:
>>
>> assert looks(Foo).like(IFoo)
>
> How very cute. And I don't mean that in a good way.
>
> Why is this a class with a method, instead of a function that takes two
> class arguments (plus any optional arguments needed)?
>
> looks_like(Foo, IFoo)
>
> is less "cute", reads better to English speakers, and much more Pythonic.
> This isn't Java, not everything needs to be a class.

I disagree.  Does that test whether Foo looks like IFoo, or IFoo looks
like Foo?  Of course, given the naming convention and the example,
it's easy to work out, but when you're trying to *write* that from
memory, it could be a nuisance to remember the proper order.  This is
already a wart of isinstance and issubclass.

looks(Foo).like(IFoo), on the other hand, is crystal clear about which
argument is which.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

duck typing assert‏ Andriy Kornatskyy <andriy.kornatskyy@live.com> - 2012-11-08 20:34 +0300
  Re: duck typing assert‏ Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-08 23:33 +0000
    Re: duck typing assert Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-08 18:00 -0700
      Re: duck typing assert Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-09 13:36 +0000
        RE: duck typing assert Andriy Kornatskyy <andriy.kornatskyy@live.com> - 2012-11-09 17:01 +0300
        Re: duck typing assert Chris Angelico <rosuav@gmail.com> - 2012-11-10 01:15 +1100
        RE: duck typing assert Andriy Kornatskyy <andriy.kornatskyy@live.com> - 2012-11-09 17:37 +0300
    Re: duck typing assert Chris Angelico <rosuav@gmail.com> - 2012-11-09 17:14 +1100
    RE: duck typing assert Andriy Kornatskyy <andriy.kornatskyy@live.com> - 2012-11-09 13:26 +0300
    RE: duck typing assert "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-09 17:37 +0000
    RE: duck typing assert Andriy Kornatskyy <andriy.kornatskyy@live.com> - 2012-11-09 20:55 +0300

csiph-web