Thomas Lotze wrote:
Log message for revision 37985:
  Simplifying some idioms, coding style.

Changed:
  U   Zope3/branches/tlotze/src/zope/interface/interface.py

-=-
Modified: Zope3/branches/tlotze/src/zope/interface/interface.py
===================================================================
--- Zope3/branches/tlotze/src/zope/interface/interface.py       2005-08-18 
07:12:23 UTC (rev 37984)
+++ Zope3/branches/tlotze/src/zope/interface/interface.py       2005-08-18 
07:57:37 UTC (rev 37985)
@@ -33,12 +33,8 @@
def invariant(call):
     f_locals = sys._getframe(1).f_locals
-    tags = f_locals.get(TAGGED_DATA)
-    if tags is None:
-        tags = f_locals[TAGGED_DATA] = {}
-    invariants = tags.get('invariants')
-    if invariants is None:
-        invariants = tags['invariants'] = []
+    tags = f_locals.setdefault(TAGGED_DATA, {})
+    invariants = tags.setdefault('invariants', [])
     invariants.append(call)
     return _decorator_non_return

I didn't review your entire check in (and I realize that this is on a branch), but the non-use of setdefault there was probably intentional to keep from constructing empty dicts and lists when they may not be used.

     def getSignatureString(self):
-        sig = "("
+        sig = []
         for v in self.positional:
-            sig = sig + v
+            sig.append(v)
             if v in self.optional.keys():
-                sig = sig + "=%s" % `self.optional[v]`
-            sig = sig + ", "
+                sig[-1] += "=%s" % `self.optional[v]`
         if self.varargs:
-            sig = sig + ("*%s, " % self.varargs)
+            sig.append("*%s" % self.varargs)
         if self.kwargs:
-            sig = sig + ("**%s, " % self.kwargs)
+            sig.append("**%s" % self.kwargs)
- # slice off the last comma and space
-        if self.positional or self.varargs or self.kwargs:
-            sig = sig[:-2]
+        return "(%s)" % ", ".join(sig)
- sig = sig + ")"
-        return sig

If you're looking for a simplification here, I'd use "+" rather than "%" above, for example:

    sig.append("*" + self.varargs)
--
Benji York
Senior Software Engineer
Zope Corporation
_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to