]> granicus.if.org Git - python/commitdiff
The one thing I love more then writing code is deleting code.
authorMoshe Zadka <moshez@math.huji.ac.il>
Mon, 29 Jan 2001 06:21:17 +0000 (06:21 +0000)
committerMoshe Zadka <moshez@math.huji.ac.il>
Mon, 29 Jan 2001 06:21:17 +0000 (06:21 +0000)
* Removed func_hash and func_compare, so they can be treated as immutable
  content-less objects (address hash and comparison)
* Added tests to that affect to test_funcattrs (also testing func_code
  is writable)
* Reverse meaning of tests in test_opcodes which checked identical code
  gets identical functions

Lib/test/test_funcattrs.py
Lib/test/test_opcodes.py
Objects/funcobject.c

index 9c07a8fee6d34023224e74f097c11350703e8c13..0591ba607a7fbf9bb51dda02976db143dac3e5da 100644 (file)
@@ -154,3 +154,22 @@ else: raise TestFailed
 # This isn't specifically related to function attributes, but it does test a
 # core dump regression in funcobject.c
 del another.func_defaults
+
+def foo():
+       pass
+
+def bar():
+       pass
+
+def temp():
+       print 1
+
+if foo==bar: raise TestFailed
+
+d={}
+d[foo] = 1
+
+foo.func_code = temp.func_code
+
+d[foo]
+
index 5381e4d94736773a9c700dc75c666a476b879938..31569d5fcbb97ada172897da5f9bd950ddd0ee07 100644 (file)
@@ -50,12 +50,12 @@ b = BClass()
 
 try: raise AClass, b
 except BClass, v:
-    if v != b: raise TestFailed
-else: raise TestFailed
+    if v != b: raise TestFailed, "v!=b"
+else: raise TestFailed, "no exception"
 
 try: raise b
 except AClass, v:
-    if v != b: raise TestFailed
+    if v != b: raise TestFailed, "v!=b AClass"
 
 # not enough arguments
 try:  raise BClass, a
@@ -64,21 +64,21 @@ except TypeError: pass
 try:  raise DClass, a
 except DClass, v:
     if not isinstance(v, DClass):
-        raise TestFailed
+        raise TestFailed, "v not DClass"
 
 print '2.3 comparing function objects'
 
 f = eval('lambda: None')
 g = eval('lambda: None')
-if f != g: raise TestFailed
+if f == g: raise TestFailed, "functions should not be same"
 
 f = eval('lambda a: a')
 g = eval('lambda a: a')
-if f != g: raise TestFailed
+if f == g: raise TestFailed, "functions should not be same"
 
 f = eval('lambda a=1: a')
 g = eval('lambda a=1: a')
-if f != g: raise TestFailed
+if f == g: raise TestFailed, "functions should not be same"
 
 f = eval('lambda: 0')
 g = eval('lambda: 1')
index b7e25aace4c7c854d94fae18ff4d7c6aa35b7e90..b166d603695e056d24ac1280618c905711cab3c8 100644 (file)
@@ -269,37 +269,6 @@ func_repr(PyFunctionObject *op)
        return PyString_FromString(buf);
 }
 
-static int
-func_compare(PyFunctionObject *f, PyFunctionObject *g)
-{
-       int c;
-       if (f->func_globals != g->func_globals)
-               return (f->func_globals < g->func_globals) ? -1 : 1;
-       if (f->func_defaults != g->func_defaults) {
-               if (f->func_defaults == NULL)
-                       return -1;
-               if (g->func_defaults == NULL)
-                       return 1;
-               c = PyObject_Compare(f->func_defaults, g->func_defaults);
-               if (c != 0)
-                       return c;
-       }
-       return PyObject_Compare(f->func_code, g->func_code);
-}
-
-static long
-func_hash(PyFunctionObject *f)
-{
-       long h,x;
-       h = PyObject_Hash(f->func_code);
-       if (h == -1) return h;
-       x = _Py_HashPointer(f->func_globals);
-       if (x == -1) return x;
-       h ^= x;
-       if (h == -1) h = -2;
-       return h;
-}
-
 static int
 func_traverse(PyFunctionObject *f, visitproc visit, void *arg)
 {
@@ -347,12 +316,12 @@ PyTypeObject PyFunction_Type = {
        0,              /*tp_print*/
        0, /*tp_getattr*/
        0, /*tp_setattr*/
-       (cmpfunc)func_compare, /*tp_compare*/
+       0, /*tp_compare*/
        (reprfunc)func_repr, /*tp_repr*/
        0,              /*tp_as_number*/
        0,              /*tp_as_sequence*/
        0,              /*tp_as_mapping*/
-       (hashfunc)func_hash, /*tp_hash*/
+       0, /*tp_hash*/
        0,              /*tp_call*/
        0,              /*tp_str*/
        (getattrofunc)func_getattro,         /*tp_getattro*/