Merge lp:~salgado/lazr.delegates/refactor-passthrough into lp:lazr.delegates

Proposed by Guilherme Salgado
Status: Rejected
Rejected by: Guilherme Salgado
Proposed branch: lp:~salgado/lazr.delegates/refactor-passthrough
Merge into: lp:lazr.delegates
Diff against target: 23 lines (+5/-2)
1 file modified
src/lazr/delegates/_delegates.py (+5/-2)
To merge this branch: bzr merge lp:~salgado/lazr.delegates/refactor-passthrough
Reviewer Review Type Date Requested Status
LAZR Developers Pending
Review via email: mp+30074@code.launchpad.net

Description of the change

This just refactors PassThrough so that subclasses have a single place to modify when they want to change the way the context is obtained. I'm going to need this on https://code.edge.launchpad.net/~salgado/lazr.restful/extension-interfaces

To post a comment you must log in.

Unmerged revisions

5. By Guilherme Salgado

Refactor Passthrough to have a single place which calls getattr(obj, self.contextvar) so that subclasses can easily change that

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lazr/delegates/_delegates.py'
2--- src/lazr/delegates/_delegates.py 2009-04-14 16:07:52 +0000
3+++ src/lazr/delegates/_delegates.py 2010-07-16 08:39:42 +0000
4@@ -113,14 +113,17 @@
5 self.name = name
6 self.contextvar = contextvar
7
8+ def _getContext(self, inst):
9+ return getattr(inst, self.contextvar)
10+
11 def __get__(self, inst, cls=None):
12 if inst is None:
13 return self
14 else:
15- return getattr(getattr(inst, self.contextvar), self.name)
16+ return getattr(self._getContext(inst), self.name)
17
18 def __set__(self, inst, value):
19- setattr(getattr(inst, self.contextvar), self.name, value)
20+ setattr(self._getContext(inst), self.name, value)
21
22 def __delete__(self, inst):
23 raise NotImplementedError

Subscribers

People subscribed via source and target branches