← Back to team overview

duplicity-team team mailing list archive

[Merge] lp:~mterry/duplicity/drop-static into lp:duplicity

 

Michael Terry has proposed merging lp:~mterry/duplicity/drop-static into lp:duplicity.

Requested reviews:
  duplicity-team (duplicity-team)

For more details, see:
https://code.launchpad.net/~mterry/duplicity/drop-static/+merge/216456

Drop static.py.

This is some of the oldest code in duplicity!  A bzr blame says it is unmodified (except for whitespace / comment changes) since revision 1.

But it's not needed anymore.  Not really even since we updated to python2.4, which introduced the @staticmethod decorator.  So this branch drops it and its test file.
-- 
https://code.launchpad.net/~mterry/duplicity/drop-static/+merge/216456
Your team duplicity-team is requested to review the proposed merge of lp:~mterry/duplicity/drop-static into lp:duplicity.
=== modified file 'duplicity/lazy.py'
--- duplicity/lazy.py	2013-12-27 06:39:00 +0000
+++ duplicity/lazy.py	2014-04-18 14:36:20 +0000
@@ -23,46 +23,51 @@
 
 import os
 
-from duplicity.static import * #@UnusedWildImport
-
 
 class Iter:
     """Hold static methods for the manipulation of lazy iterators"""
 
+    @staticmethod
     def filter(predicate, iterator): #@NoSelf
         """Like filter in a lazy functional programming language"""
         for i in iterator:
             if predicate(i):
                 yield i
 
+    @staticmethod
     def map(function, iterator): #@NoSelf
         """Like map in a lazy functional programming language"""
         for i in iterator:
             yield function(i)
 
+    @staticmethod
     def foreach(function, iterator): #@NoSelf
         """Run function on each element in iterator"""
         for i in iterator:
             function(i)
 
+    @staticmethod
     def cat(*iters): #@NoSelf
         """Lazily concatenate iterators"""
         for iter in iters:
             for i in iter:
                 yield i
 
+    @staticmethod
     def cat2(iter_of_iters): #@NoSelf
         """Lazily concatenate iterators, iterated by big iterator"""
         for iter in iter_of_iters:
             for i in iter:
                 yield i
 
+    @staticmethod
     def empty(iter): #@NoSelf
         """True if iterator has length 0"""
         for i in iter: #@UnusedVariable
             return None
         return 1
 
+    @staticmethod
     def equal(iter1, iter2, verbose = None, operator = lambda x, y: x == y): #@NoSelf
         """True if iterator 1 has same elements as iterator 2
 
@@ -88,6 +93,7 @@
             print "End when i2 = %s" % (i2,)
         return None
 
+    @staticmethod
     def Or(iter): #@NoSelf
         """True if any element in iterator is true.  Short circuiting"""
         i = None
@@ -96,6 +102,7 @@
                 return i
         return i
 
+    @staticmethod
     def And(iter): #@NoSelf
         """True if all elements in iterator are true.  Short circuiting"""
         i = 1
@@ -104,6 +111,7 @@
                 return i
         return i
 
+    @staticmethod
     def len(iter): #@NoSelf
         """Return length of iterator"""
         i = 0
@@ -114,6 +122,7 @@
                 return i
             i = i+1
 
+    @staticmethod
     def foldr(f, default, iter): #@NoSelf
         """foldr the "fundamental list recursion operator"?"""
         try:
@@ -122,6 +131,7 @@
             return default
         return f(next, Iter.foldr(f, default, iter))
 
+    @staticmethod
     def foldl(f, default, iter): #@NoSelf
         """the fundamental list iteration operator.."""
         while 1:
@@ -131,6 +141,7 @@
                 return default
             default = f(default, next)
 
+    @staticmethod
     def multiplex(iter, num_of_forks, final_func = None, closing_func = None): #@NoSelf
         """Split a single iterater into a number of streams
 
@@ -191,8 +202,6 @@
 
         return tuple(map(make_iterator, range(num_of_forks)))
 
-MakeStatic(Iter)
-
 
 class IterMultiplex2:
     """Multiplex an iterator into 2 parts

=== removed file 'duplicity/static.py'
--- duplicity/static.py	2009-04-01 15:07:45 +0000
+++ duplicity/static.py	1970-01-01 00:00:00 +0000
@@ -1,46 +0,0 @@
-# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
-#
-# Copyright 2002 Ben Escoto <ben@xxxxxxxxxxx>
-# Copyright 2007 Kenneth Loafman <kenneth@xxxxxxxxxxx>
-#
-# This file is part of duplicity.
-#
-# Duplicity is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation; either version 2 of the License, or (at your
-# option) any later version.
-#
-# Duplicity is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with duplicity; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-"""MakeStatic and MakeClass
-
-These functions are used to make all the instance methods in a class
-into static or class methods.
-
-"""
-
-class StaticMethodsError(Exception): pass
-
-def MakeStatic(cls):
-    """turn instance methods into static ones
-
-    The methods (that don't begin with _) of any class that
-    subclasses this will be turned into static methods.
-
-    """
-    for name in dir(cls):
-        if name[0] != "_":
-            cls.__dict__[name] = staticmethod(cls.__dict__[name])
-
-def MakeClass(cls):
-    """Turn instance methods into classmethods.  Ignore _ like above"""
-    for name in dir(cls):
-        if name[0] != "_":
-            cls.__dict__[name] = classmethod(cls.__dict__[name])

=== modified file 'po/POTFILES.in'
--- po/POTFILES.in	2014-04-17 19:34:23 +0000
+++ po/POTFILES.in	2014-04-18 14:36:20 +0000
@@ -16,7 +16,6 @@
 duplicity/log.py
 duplicity/robust.py
 duplicity/misc.py
-duplicity/static.py
 duplicity/diffdir.py
 duplicity/lazy.py
 duplicity/backends/_cf_pyrax.py

=== removed file 'testing/tests/test_static.py'
--- testing/tests/test_static.py	2014-04-16 02:43:43 +0000
+++ testing/tests/test_static.py	1970-01-01 00:00:00 +0000
@@ -1,86 +0,0 @@
-# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
-#
-# Copyright 2002 Ben Escoto <ben@xxxxxxxxxxx>
-# Copyright 2007 Kenneth Loafman <kenneth@xxxxxxxxxxx>
-#
-# This file is part of duplicity.
-#
-# Duplicity is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation; either version 2 of the License, or (at your
-# option) any later version.
-#
-# Duplicity is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with duplicity; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import helper
-import unittest, types, sys
-
-from duplicity.static import * #@UnusedWildImport
-
-helper.setup()
-
-class D:
-    def foo(x, y): #@NoSelf
-        return x, y
-    def bar(self, x):
-        return 3, x
-    def _hello(self):
-        return self
-
-MakeStatic(D)
-
-
-class C:
-    _a = 0
-    def get(cls): #@NoSelf
-        return cls._a
-    def inc(cls): #@NoSelf
-        cls._a = cls._a + 1
-
-MakeClass(C)
-
-
-class StaticMethodsTest(unittest.TestCase):
-    """Test StaticMethods module"""
-    def testType(self):
-        """Methods should have type StaticMethod"""
-        assert type(D.foo) is types.FunctionType
-        assert type(D.bar) is types.FunctionType
-
-    def testStatic(self):
-        """Methods should be callable without instance"""
-        assert D.foo(1,2) == (1,2)
-        assert D.bar(3,4) == (3,4)
-
-    def testBound(self):
-        """Methods should also work bound"""
-        d = D()
-        assert d.foo(1,2) == (1,2)
-        assert d.bar(3,4) == (3,4)
-
-    def testStatic_(self):
-        """_ Methods should be untouched"""
-        d = D()
-        self.assertRaises(TypeError, d._hello, 4)
-        assert d._hello() is d
-
-
-class ClassMethodsTest(unittest.TestCase):
-    def test(self):
-        """Test MakeClass function"""
-        assert C.get() == 0
-        C.inc()
-        assert C.get() == 1
-        C.inc()
-        assert C.get() == 2
-
-
-if __name__ == "__main__":
-    unittest.main()


Follow ups