telepathy-mission-control: enable_fakecm_account: copy parameters and alter the copy

Simon McVittie smcv at kemper.freedesktop.org
Tue Oct 9 09:11:24 PDT 2012


Module: telepathy-mission-control
Branch: master
Commit: 121688c19cded284257b9e7a3690207d98899f82
URL:    http://cgit.freedesktop.org/telepathy/telepathy-mission-control/commit/?id=121688c19cded284257b9e7a3690207d98899f82

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Fri Oct  5 13:21:16 2012 +0100

enable_fakecm_account: copy parameters and alter the copy

Mutable defaults for arguments are dangerous. If we call
enable_fakecm_account twice with default arguments, when we alter
expect_before_connect/expect_after_connect, we are actually altering
the default! Python doesn't construct a new empty list for us every
time. The C equivalent would be a static GPtrArray * or something.

---

 tests/twisted/mctest.py |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/tests/twisted/mctest.py b/tests/twisted/mctest.py
index be187d6..e6eff4a 100644
--- a/tests/twisted/mctest.py
+++ b/tests/twisted/mctest.py
@@ -946,8 +946,12 @@ def expect_fakecm_connection(q, bus, mc, account, expected_params,
         has_requests=True, has_presence=False, has_aliasing=False,
         has_avatars=False, avatars_persist=True,
         extra_interfaces=[],
-        expect_before_connect=[], expect_after_connect=[],
+        expect_before_connect=(), expect_after_connect=(),
         has_hidden=False):
+    # make (safely) mutable copies
+    expect_before_connect = list(expect_before_connect)
+    expect_after_connect = list(expect_after_connect)
+
     e = q.expect('dbus-method-call', method='RequestConnection',
             args=['fakeprotocol', expected_params],
             destination=cs.tp_name_prefix + '.ConnectionManager.fakecm',



More information about the telepathy-commits mailing list