[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-dev
Subject:    Re: [Python-Dev] Re: __except__ use cases
From:       John J Lee <jjl () pobox ! com>
Date:       2005-04-24 17:12:03
Message-ID: Pine.LNX.4.58.0504241705050.6803 () alice
[Download RAW message or body]

On Sun, 24 Apr 2005, Nick Coghlan wrote:
[...]
> Seeing this example has convinced me of something. PEP 310 should use the 'with' 
> keyword, and 'expression block' syntax should be used to denote the 'default 
> object' semantics proposed for Python 3K. For example:
> 
> class Key2AttributeError(object):
>      def __init__(self, obj, attr):
>          self:
>              .obj_type = type(obj)
>              .attr = attr
>      def __except__(self, ex_type, ex_val, ex_tb):
>          if isinstance(ex_type, KeyError):
>               self:
>                   raise AttributeError("%s instance has no attribute %s"
>                                         % (.obj_type, .attr))
> 
> > # Somewhere else. . .
>      def __getattr__(self, name):
>          with Key2AttributeError(self, key):
>              self:
>                  return ._cache[key]
[...]

+1

Purely based on my aesthetic reaction, that is.  Never having used other
languages with this 'attribute lookup shorthand' feature, that seems to
align *much* more with what I expect than the other way around.  If 'with'
is used in other languages as the keyword for attribute lookup shorthand,
though, perhaps it will confuse other people, or at least make them frown
:-(


John
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/python-dev%40progressive-comp.com
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic