Merge lp:~jderose/desktopcouch/ctx-should-default-to-None into lp:desktopcouch

Proposed by Jason Gerard DeRose
Status: Merged
Approved by: Vincenzo Di Somma
Approved revision: 200
Merged at revision: 211
Proposed branch: lp:~jderose/desktopcouch/ctx-should-default-to-None
Merge into: lp:desktopcouch
Diff against target: 14 lines (+3/-1)
1 file modified
desktopcouch/records/server.py (+3/-1)
To merge this branch: bzr merge lp:~jderose/desktopcouch/ctx-should-default-to-None
Reviewer Review Type Date Requested Status
Vincenzo Di Somma (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+40313@code.launchpad.net

Commit message

Make context function-argument default-value None so that callers need not concern themselves with complex imports.

Description of the change

Small change to make it easier for 3rd-party apps to use destopcouch test idioms (this is a problem for dmedia).

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

I think I'm missing the point of this change. In what scenario would this make a difference? Is it to do with the import time instantiation of default arguments?

Revision history for this message
Jason Gerard DeRose (jderose) wrote :

It's so that internal details (that ctx defaults to desktopcouch.local_files.DEFAULT_CONTEXT) don't leak into subclasses, other functions/classes using it. It's also best-practice in the Python standard library... optional/keyword args default to simple, predictable values, most often None, sometime True/False, etc.

For example, in dmedia I need to provide a custom context when testing (Chad help me with this so I can test the same way desktopcouch itself does), but I don't want to deal with the desktopcouch.local_files.DEFAULT_CONTEXT detail myself.

See the dmedia MetaStore.__init__() on line 109: http://bazaar.launchpad.net/~jderose/dmedia/trunk/annotate/head%3A/dmedialib/metastore.py?start_revid=104

Revision history for this message
Eric Casteleijn (thisfred) wrote :

Fair enough, and I agree with keeping default kw arguments as simple as possible, since they can definitely bite you on the ass if you don't :)

review: Approve
Revision history for this message
Vincenzo Di Somma (vds) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/records/server.py'
2--- desktopcouch/records/server.py 2010-11-04 11:01:31 +0000
3+++ desktopcouch/records/server.py 2010-11-08 10:41:55 +0000
4@@ -60,7 +60,9 @@
5
6 def __init__(self, database, uri=None, record_factory=None, create=False,
7 server_class=OAuthCapableServer, oauth_tokens=None,
8- ctx=desktopcouch.local_files.DEFAULT_CONTEXT):
9+ ctx=None):
10+ if ctx is None:
11+ ctx = desktopcouch.local_files.DEFAULT_CONTEXT
12 self.ctx = ctx
13 self.server_uri = uri
14 super(CouchDatabase, self).__init__(

Subscribers

People subscribed via source and target branches