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


Groups > comp.lang.python > #44704

Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError.

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!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.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'attribute': 0.07; 'incompatible': 0.07; 'nicely': 0.07; 'code"': 0.09; 'decorator': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'works.': 0.09; 'python': 0.11; 'def': 0.12; 'backward': 0.16; 'lambda': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'surprises': 0.16; 'syntactic': 0.16; 'subject:python': 0.16; 'language': 0.16; 'code.': 0.18; 'solution.': 0.20; 'work,': 0.20; 'header:User-Agent:1': 0.23; '(such': 0.24; 'decorators': 0.24; 'together.': 0.24; 'developers': 0.25; 'equivalent': 0.26; 'header:X-Complaints-To:1': 0.27; 'correct': 0.29; 'towards': 0.31; 'writes:': 0.31; 'allows': 0.31; 'compatible': 0.32; 'problem': 0.35; 'subject:with': 0.35; 'problem.': 0.35; 'but': 0.35; 'there': 0.35; 'charset:us-ascii': 0.36; 'should': 0.36; 'two': 0.37; 'level': 0.37; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'easy': 0.60; 'solve': 0.60; 'received:217': 0.63; 'behavior': 0.77; 'subject:skip:A 10': 0.78; 'hate': 0.91; 'hand,': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From dieter <dieter@handshake.de>
Subject Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError.
Date Sat, 04 May 2013 07:56:22 +0200
References <mailman.1257.1367537690.3114.python-list@python.org> <518302d7$0$29971$c3e8da3$5496439d@news.astraweb.com> <CAJxoosf4NLafEKHy3CSk1GBSO2RCxk_9SsxPHraOa-JU45jByg@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Gmane-NNTP-Posting-Host pd9e08eb0.dip0.t-ipconnect.de
User-Agent Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux)
Cancel-Lock sha1:FRjldeDA6XbDLIqMq0hUQ2p3sBg=
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.1285.1367646997.3114.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1367646997 news.xs4all.nl 15933 [2001:888:2000:d::a6]:46844
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:44704

Show key headers only | View raw


"Mr. Joe" <titanix88@gmail.com> writes:

> ...
> Then I came to know that 'property' does not play well
> with polymorphic code. :(

Can you elaborate?

I like "polymorphic code" and decorators (such a "property")
never met a problem with the two working nicely together.

> I resorted to some lambda hacks learned from
> stackoverflow.com to solve the problem. I know that it's the correct way
> for decorators to work, but still, it would be nice to have a language
> level solution.

There are two approaches: change the language or learn how the language works.

I am very happy that the Python developers try hard to retain backward
compatible and, consequently, are very reluctant towards language changes.
I would hate should the decorator behavior change in an incompatible
way.

On the other hand, decorators are very easy to understand: they are
just syntactic sugar:

     @<dec_expression>
     def f(...): ...

  is equivalent to:

     def f(...): ...
     f = <dec_expression>(f)

The "property" decorator uses an additional concept: "descriptor"s.
A "descriptor" allows you to customize attribute access.

These two concepts graped, the "property" decorator should no longer
cause surprises -- even in "polymorphic code".

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


Thread

Debugging difficulty in python with __getattr__, decorated properties and AttributeError. "Mr. Joe" <titanix88@gmail.com> - 2013-05-03 05:34 +0600
  Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-03 00:20 +0000
    Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError. "Mr. Joe" <titanix88@gmail.com> - 2013-05-03 13:52 +0600
      Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-04 06:29 +0000
        Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError. "Mr. Joe" <titanix88@gmail.com> - 2013-05-14 21:09 +0600
        Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError. dieter <dieter@handshake.de> - 2013-05-15 08:15 +0200
        Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError. "Mr. Joe" <titanix88@gmail.com> - 2013-05-15 22:38 +0600
    Re: Debugging difficulty in python with __getattr__, decorated properties and AttributeError. dieter <dieter@handshake.de> - 2013-05-04 07:56 +0200

csiph-web