Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32979
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; '21,': 0.07; 'welcome.': 0.07; 'python': 0.09; "'''": 0.09; '@property': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'typed': 0.09; 'def': 0.10; 'language,': 0.11; 'programmer': 0.11; 'interfaces': 0.15; 'classes:': 0.16; 'foo(object):': 0.16; 'principal.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'typing': 0.17; 'jan': 0.18; 'import': 0.21; 'error.': 0.21; 'programming': 0.23; 'this:': 0.23; 'user.': 0.23; 'properties': 0.24; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; '(most': 0.27; 'strongly': 0.27; 'header:X-Complaints-To:1': 0.28; 'post': 0.28; 'assert': 0.29; 'class': 0.29; 'url:2012': 0.30; 'file': 0.32; 'good.': 0.32; 'comments': 0.33; 'traceback': 0.33; 'to:addr :python-list': 0.33; 'languages': 0.33; 'pm,': 0.35; 'something': 0.35; 'received:org': 0.36; 'two': 0.37; 'being': 0.37; 'far': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'shows': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'between': 0.63; 'url:blogspot': 0.64; 'here': 0.65; 'offer': 0.65; 'lack': 0.71; 'url:11': 0.71; 'subjectcharset:utf-8': 0.72; 'received:fios.verizon.net': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Terry Reedy <tjreedy@udel.edu> |
| Subject | Re: duck typing assert |
| Date | Thu, 08 Nov 2012 15:39:24 -0500 |
| References | <DUB117-W18E06D840F2407846F709191690@phx.gbl> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | pool-173-75-251-66.phlapa.fios.verizon.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0 |
| In-Reply-To | <DUB117-W18E06D840F2407846F709191690@phx.gbl> |
| 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.3464.1352407186.27098.python-list@python.org> (permalink) |
| Lines | 59 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1352407186 news.xs4all.nl 6936 [2001:888:2000:d::a6]:43050 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:32979 |
Show key headers only | View raw
On 11/8/2012 12:34 PM, 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)
>
> The post below shows how programmer can assert duck typing between
> two Python classes:
>
> http://mindref.blogspot.com/2012/11/python-duck-typing-assert.html
>
> Comments or suggestions are welcome.
From the post:
'''
So far so good. Let fix it and take a look at properties:
from wheezy.core.introspection import looks
class IFoo(object):
def foo(self, a, b=None):
pass
@property
def bar(self):
pass
class Foo(object):
def foo(self, a, b=None):
pass
def bar(self):
pass
assert looks(Foo).like(IFoo)
Here is output:
test.py:21: UserWarning: 'bar': is not property.
assert looks(Foo).like(IFoo)
Traceback (most recent call last):
File "test.py", line 21, in
assert looks(Foo).like(IFoo)
AssertionError
'''
I view this check as an error. Properties are intended to be transparent
to the user. One use of properties is to make something that is not a
Mallard act like a Mallard. So this check breaks duck typing.
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: duck typing assert Terry Reedy <tjreedy@udel.edu> - 2012-11-08 15:39 -0500
Re: duck typing assert Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-08 23:40 +0000
Re: duck typing assert Terry Reedy <tjreedy@udel.edu> - 2012-11-08 23:44 -0500
Re: duck typing assert Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-09 06:30 +0000
Re: duck typing assert Terry Reedy <tjreedy@udel.edu> - 2012-11-09 12:03 -0500
csiph-web