]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Use descriptors.
authorGuido van Rossum <guido@python.org>
Sun, 16 Jan 2005 00:25:31 +0000 (00:25 +0000)
committerGuido van Rossum <guido@python.org>
Sun, 16 Jan 2005 00:25:31 +0000 (00:25 +0000)
Lib/test/test_datetime.py
Lib/test/test_descr.py
Lib/test/test_descrtut.py
Lib/test/test_doctest2.py
Lib/test/test_userdict.py

index d1f312da7eadd5a34acd91ee54e9ff49a2ceb304..9abfb875b9a79554891a5dceb0c4a322d8168e9a 100644 (file)
@@ -446,9 +446,9 @@ class TestTimeDelta(HarmlessMixedComparison):
     def test_subclass_timedelta(self):
 
         class T(timedelta):
+            @staticmethod
             def from_td(td):
                 return T(td.days, td.seconds, td.microseconds)
-            from_td = staticmethod(from_td)
 
             def as_hours(self):
                 sum = (self.days * 24 +
index f1abd3a503dbc2321b54224c55189cb715cc8657..c1bd00d84ba46282d54e9a6f3561dedb9ce496f8 100644 (file)
@@ -691,13 +691,13 @@ def metaclass():
     class _instance(object):
         pass
     class M2(object):
+        @staticmethod
         def __new__(cls, name, bases, dict):
             self = object.__new__(cls)
             self.name = name
             self.bases = bases
             self.dict = dict
             return self
-        __new__ = staticmethod(__new__)
         def __call__(self):
             it = _instance()
             # Early binding of methods
@@ -2071,9 +2071,9 @@ def supers():
         aProp = property(lambda self: "foo")
 
     class Sub(Base):
+        @classmethod
         def test(klass):
             return super(Sub,klass).aProp
-        test = classmethod(test)
 
     veris(Sub.test(), Base.aProp)
 
index 851ce4a93cf1780aee4b97e722bebe46e2156981..9dcfca1961e7a15d47d7dfa4d8d0d9cb8c46942f 100644 (file)
@@ -246,9 +246,9 @@ static methods in C++ or Java. Here's an example:
 
     >>> class C:
     ...
+    ...     @staticmethod
     ...     def foo(x, y):
     ...         print "staticmethod", x, y
-    ...     foo = staticmethod(foo)
 
     >>> C.foo(1, 2)
     staticmethod 1 2
@@ -260,9 +260,9 @@ Class methods use a similar pattern to declare methods that receive an
 implicit first argument that is the *class* for which they are invoked.
 
     >>> class C:
+    ...     @classmethod
     ...     def foo(cls, y):
     ...         print "classmethod", cls, y
-    ...     foo = classmethod(foo)
 
     >>> C.foo(1)
     classmethod test.test_descrtut.C 1
@@ -286,10 +286,10 @@ call, not the class involved in the definition of foo().
 But notice this:
 
     >>> class E(C):
+    ...     @classmethod
     ...     def foo(cls, y): # override C.foo
     ...         print "E.foo() called"
     ...         C.foo(y)
-    ...     foo = classmethod(foo)
 
     >>> E.foo(1)
     E.foo() called
index 5b7f36f0f738d94b8f96b30a0141b374f6dccaa2..865a32e6f250de81239232320876988d671d0b03 100644 (file)
@@ -80,6 +80,7 @@ class C(object):
         -12
         """)
 
+    @staticmethod
     def statm():
         """
         A static method.
@@ -91,8 +92,7 @@ class C(object):
         """
         return 666
 
-    statm = staticmethod(statm)
-
+    @classmethod
     def clsm(cls, val):
         """
         A class method.
@@ -104,8 +104,6 @@ class C(object):
         """
         return val
 
-    clsm = classmethod(clsm)
-
 def test_main():
     from test import test_doctest2
     EXPECTED = 19
index cc5b0edc6bc6bfc3e69a5f7e7d32388188364148..2d5fa0304f1c2969e9fcc49dca6bc02062e0a649 100644 (file)
@@ -191,12 +191,12 @@ class SeqDict(UserDict.DictMixin):
         for key, value in self.iteritems():
             d[key] = value
         return d
+    @classmethod
     def fromkeys(cls, keys, value=None):
         d = cls()
         for key in keys:
             d[key] = value
         return d
-    fromkeys = classmethod(fromkeys)
 
 class UserDictMixinTest(mapping_tests.TestMappingProtocol):
     type2test = SeqDict