Wrapping up 'dynamic attribute' discussion

I've sent an updated version of PEP 363 to the editors, which includes the following summary of the discussion. I hope I've captured the important points, but please let me know if there's something important I've left out or misrepresented. - - - - 8< - - - - Mailing Lists Discussion Initial posting of this PEP in draft form was to python-ideas on 20070209 [2], and the response was generally positive. The PEP was then posted to python-dev on 20070212 [3], and an interesting discussion ensued. A brief summary: Initially, there was reasonable (but not unanimous) support for the idea, although the precise choice of syntax had a more mixed reception. Several people thought the "." would be too easily overlooked, with the result that the syntax could be confused with a method/function call. A few alternative syntaxes were suggested: obj.(foo) obj.[foo] obj.{foo} obj{foo} obj.*foo obj->foo obj<-foo obj@foo obj.[[foo]] with "obj.[foo]" emerging as the preferred one. In this initial discussion, the two-argument form was universally disliked, so it was to be taken out of the PEP. Discussion then took a step back to whether this particular feature provided enough benefit to justify new syntax. As well as requiring coders to become familiar with the new syntax, there would also be the problem of backward compatibility --- code using the new syntax would not run on older pythons. Instead of new syntax, a new "wrapper class" was proposed, with the following specification / conceptual implementation suggested by Martin Loewis: class attrs: def __init__(self, obj): self.obj = obj def __getitem__(self, name): return getattr(self.obj, name) def __setitem__(self, name, value): return setattr(self.obj, name, value) def __delitem__(self, name): return delattr(self, name) def __contains__(self, name): return hasattr(self, name) This was considered a cleaner and more elegant solution to the original problem. The decision was made that the present PEP did not meet the burden of proof for the introduction of new syntax, a view which had been put forward by some from the beginning of the discussion. The wrapper class idea was left open as a possibility for a future PEP.

On Friday 16 February 2007 09:08, Ben North wrote:
Instead of new syntax, a new "wrapper class" was proposed, with the following specification / conceptual implementation suggested by Martin Loewis:
...snip...
This was considered a cleaner and more elegant solution to the original problem. The decision was made that the present PEP did not meet the burden of proof for the introduction of new syntax, a view which had been put forward by some from the beginning of the discussion. The wrapper class idea was left open as a possibility for a future PEP.
A good first step would be to contribute something like this to the Python Cookbook, if it isn't already there. -- Anthony Baxter <anthony@interlink.com.au> It's never too late to have a happy childhood.

On 2/15/07, Anthony Baxter <anthony@interlink.com.au> wrote:
On Friday 16 February 2007 09:08, Ben North wrote:
The wrapper class idea was left open as a possibility for a future PEP.
A good first step would be to contribute something like this to the Python Cookbook, if it isn't already there.
I could not find such a class in the cookbook. (That's not to say there's not one there that I missed.) Because I think attrview() should happen, I submitted a recipe to the Python Cookbook. While it awaits editor approval, I have it posted at http://www.verylowsodium.com/attrview.py . One possibly controversial design choice here: since there is no guaranteed way to enumerate attributes in the face of __getattr__ and friends, my version of attrview() does not provide iteration or any other operation that assumes object attributes can be enumerated. Therefore, it technically does not implement a mapping. Once Python grows a __dir__ special method, it's possible I could be convinced this is the wrong choice, but I'm not sure of that. Greg F
participants (3)
-
Anthony Baxter
-
Ben North
-
Greg Falcon