[New-bugs-announce] [issue14293] Message methods delegated via __getattr__ inaccessible using super().<method>

Brian Jones report at bugs.python.org
Tue Mar 13 23:12:53 CET 2012

New submission from Brian Jones <bkjones at gmail.com>:

In email6, the message.Message class tries to delegate calls to methods not defined in Message to message._HeaderList. However, delegating in this way makes the methods inaccessible when accessing them through a call to super(). This comes into play in the http.HTTPMessage class, which attempts to call the _HeaderList 'get' method as 'super().get()'. An AttributeError is raised in this case, because super is only examining the class, and not the instance, and isn't executing __getattr__ to get at methods defined in _HeaderList methods. 

I've attached a patch that only patches the appropriate test module to add a test to prove the failure. The fix involves a bit more complexity, and I've had some trouble getting my brain to not reject the kind of conflation of concepts and overlapping of responsibility that needs to take place to implement the ideas I was able to come up with. I'm happy to help implement a sane solution if anyone has other ideas. 

A couple of ideas that came up (at the PyCon sprints) were: 

1.  Make _HeaderList *not* extend 'list', and then have Message inherit from _HeaderList. However, that means basically reimplementing all of the methods in the 'list' interface inside of _HeaderList, and by extension, Message becomes something of a 'list' object for the purpose of header manipulation, but not for anything else (like, say, payload). 

2. Just get rid of _HeaderList and put it all inside of Message. See item 1 for issues with this idea. 

3. Expose a public 'headers' attribute, which opens a lot of doors in terms of design flexibility, elegance, and cleanliness, but changes the API. 

4. Create a base class that defines the non-list-specific interface for _HeaderList. _HeaderList would then inherit from this class, adding the list-specific methods on top, and Message would inherit it and only override non-list-specific methods. This could have some benefits in terms of testing, but arguably it muddies the waters for those maintaining/extending the _HeaderList or Message code.

Other ideas? Also let me know if I've done something silly in writing the test to trigger the problem.

components: Library (Lib)
files: msg_api_subclass_bug_test.patch
keywords: patch
messages: 155679
nosy: Brian.Jones, r.david.murray
priority: normal
severity: normal
status: open
title: Message methods delegated via __getattr__ inaccessible using super().<method>
versions: Python 3.3
Added file: http://bugs.python.org/file24829/msg_api_subclass_bug_test.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list