File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -154,3 +154,22 @@ def another():
154154# This isn't specifically related to function attributes, but it does test a
155155# core dump regression in funcobject.c
156156del another .func_defaults
157+
158+ def foo ():
159+ pass
160+
161+ def bar ():
162+ pass
163+
164+ def temp ():
165+ print 1
166+
167+ if foo == bar : raise TestFailed
168+
169+ d = {}
170+ d [foo ] = 1
171+
172+ foo .func_code = temp .func_code
173+
174+ d [foo ]
175+
Original file line number Diff line number Diff line change @@ -50,12 +50,12 @@ def __init__(self, ignore):
5050
5151try : raise AClass , b
5252except BClass , v :
53- if v != b : raise TestFailed
54- else : raise TestFailed
53+ if v != b : raise TestFailed , "v!=b"
54+ else : raise TestFailed , "no exception"
5555
5656try : raise b
5757except AClass , v :
58- if v != b : raise TestFailed
58+ if v != b : raise TestFailed , "v!=b AClass"
5959
6060# not enough arguments
6161try : raise BClass , a
@@ -64,21 +64,21 @@ def __init__(self, ignore):
6464try : raise DClass , a
6565except DClass , v :
6666 if not isinstance (v , DClass ):
67- raise TestFailed
67+ raise TestFailed , "v not DClass"
6868
6969print '2.3 comparing function objects'
7070
7171f = eval ('lambda: None' )
7272g = eval ('lambda: None' )
73- if f != g : raise TestFailed
73+ if f == g : raise TestFailed , "functions should not be same"
7474
7575f = eval ('lambda a: a' )
7676g = eval ('lambda a: a' )
77- if f != g : raise TestFailed
77+ if f == g : raise TestFailed , "functions should not be same"
7878
7979f = eval ('lambda a=1: a' )
8080g = eval ('lambda a=1: a' )
81- if f != g : raise TestFailed
81+ if f == g : raise TestFailed , "functions should not be same"
8282
8383f = eval ('lambda: 0' )
8484g = eval ('lambda: 1' )
Original file line number Diff line number Diff line change @@ -269,37 +269,6 @@ func_repr(PyFunctionObject *op)
269269 return PyString_FromString (buf );
270270}
271271
272- static int
273- func_compare (PyFunctionObject * f , PyFunctionObject * g )
274- {
275- int c ;
276- if (f -> func_globals != g -> func_globals )
277- return (f -> func_globals < g -> func_globals ) ? -1 : 1 ;
278- if (f -> func_defaults != g -> func_defaults ) {
279- if (f -> func_defaults == NULL )
280- return -1 ;
281- if (g -> func_defaults == NULL )
282- return 1 ;
283- c = PyObject_Compare (f -> func_defaults , g -> func_defaults );
284- if (c != 0 )
285- return c ;
286- }
287- return PyObject_Compare (f -> func_code , g -> func_code );
288- }
289-
290- static long
291- func_hash (PyFunctionObject * f )
292- {
293- long h ,x ;
294- h = PyObject_Hash (f -> func_code );
295- if (h == -1 ) return h ;
296- x = _Py_HashPointer (f -> func_globals );
297- if (x == -1 ) return x ;
298- h ^= x ;
299- if (h == -1 ) h = -2 ;
300- return h ;
301- }
302-
303272static int
304273func_traverse (PyFunctionObject * f , visitproc visit , void * arg )
305274{
@@ -347,12 +316,12 @@ PyTypeObject PyFunction_Type = {
347316 0 , /*tp_print*/
348317 0 , /*tp_getattr*/
349318 0 , /*tp_setattr*/
350- ( cmpfunc ) func_compare , /*tp_compare*/
319+ 0 , /*tp_compare*/
351320 (reprfunc )func_repr , /*tp_repr*/
352321 0 , /*tp_as_number*/
353322 0 , /*tp_as_sequence*/
354323 0 , /*tp_as_mapping*/
355- ( hashfunc ) func_hash , /*tp_hash*/
324+ 0 , /*tp_hash*/
356325 0 , /*tp_call*/
357326 0 , /*tp_str*/
358327 (getattrofunc )func_getattro , /*tp_getattro*/
You can’t perform that action at this time.
0 commit comments