diff options
author | Christian Heimes <christian@cheimes.de> | 2007-11-27 10:40:20 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2007-11-27 10:40:20 (GMT) |
commit | ff737954f3ee3005236133fc51b55a508b11aa06 (patch) | |
tree | b65ae9e39e774bd73674b5088e549d09a7bfd7d6 /Lib/test | |
parent | 0d3fb8a944a810f421377d5823cbc006700b3c1d (diff) | |
download | cpython-ff737954f3ee3005236133fc51b55a508b11aa06.zip cpython-ff737954f3ee3005236133fc51b55a508b11aa06.tar.gz cpython-ff737954f3ee3005236133fc51b55a508b11aa06.tar.bz2 |
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Also removed im_class and renamed im_self to __self__ and im_func to __func__. im_class can be substituted with method.__self__.__class__.
I've also updated some parts of the documenation.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/crashers/borrowed_ref_2.py | 2 | ||||
-rw-r--r-- | Lib/test/test_descr.py | 31 | ||||
-rw-r--r-- | Lib/test/test_funcattrs.py | 41 | ||||
-rw-r--r-- | Lib/test/test_new.py | 4 | ||||
-rw-r--r-- | Lib/test/test_profilehooks.py | 2 | ||||
-rw-r--r-- | Lib/test/test_pyclbr.py | 2 |
6 files changed, 36 insertions, 46 deletions
diff --git a/Lib/test/crashers/borrowed_ref_2.py b/Lib/test/crashers/borrowed_ref_2.py index f3ca350..6e403eb 100644 --- a/Lib/test/crashers/borrowed_ref_2.py +++ b/Lib/test/crashers/borrowed_ref_2.py @@ -33,6 +33,6 @@ lst = [None] * 1000000 i = 0 del a while 1: - c.d = 42 # segfaults in PyMethod_New(im_func=D.__set__, im_self=d) + c.d = 42 # segfaults in PyMethod_New(__func__=D.__set__, __self__=d) lst[i] = c.g # consume the free list of instancemethod objects i += 1 diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index e093ce8..a518f16 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -280,12 +280,12 @@ def test_dir(): c = C() vereq(interesting(dir(c)), cstuff) - #verify('im_self' in dir(C.Cmethod)) + #verify('__self__' in dir(C.Cmethod)) c.cdata = 2 c.cmethod = lambda self: 0 vereq(interesting(dir(c)), cstuff + ['cdata', 'cmethod']) - #verify('im_self' in dir(c.Cmethod)) + #verify('__self__' in dir(c.Cmethod)) class A(C): Adata = 1 @@ -293,13 +293,13 @@ def test_dir(): astuff = ['Adata', 'Amethod'] + cstuff vereq(interesting(dir(A)), astuff) - #verify('im_self' in dir(A.Amethod)) + #verify('__self__' in dir(A.Amethod)) a = A() vereq(interesting(dir(a)), astuff) a.adata = 42 a.amethod = lambda self: 3 vereq(interesting(dir(a)), astuff + ['adata', 'amethod']) - #verify('im_self' in dir(a.Amethod)) + #verify('__self__' in dir(a.Amethod)) # Try a module subclass. import sys @@ -1418,10 +1418,10 @@ def classmethods(): vereq(ff.__get__(0)(42), (int, 42)) # Test super() with classmethods (SF bug 535444) - veris(C.goo.im_self, C) - veris(D.goo.im_self, D) - veris(super(D,D).goo.im_self, D) - veris(super(D,d).goo.im_self, D) + veris(C.goo.__self__, C) + veris(D.goo.__self__, D) + veris(super(D,D).goo.__self__, D) + veris(super(D,d).goo.__self__, D) vereq(super(D,D).goo(), (D,)) vereq(super(D,d).goo(), (D,)) @@ -1507,7 +1507,7 @@ def classic(): r = repr(E().foo) verify(r.startswith("<bound method E.foo "), r) r = repr(C.foo.__get__(C())) - verify(r.startswith("<bound method ?.foo "), r) + verify(r.startswith("<bound method "), r) def compattr(): if verbose: print("Testing computed attributes...") @@ -1687,7 +1687,7 @@ def methods(): vereq(d2.goo(), 1) class E(object): foo = C.foo - vereq(E().foo.im_func, C.foo) # i.e., unbound + vereq(E().foo.__func__, C.foo) # i.e., unbound r = repr(C.foo.__get__(C(1))) verify(r.startswith("<bound method "), r) @@ -1864,17 +1864,6 @@ def recursions(): ## raise TestFailed, "expected a RuntimeError for print recursion" ## sys.stdout = test_stdout - # Bug #1202533. - class A(object): - pass - A.__mul__ = new.instancemethod(lambda self, x: self * x, None, A) - try: - A()*2 - except RuntimeError: - pass - else: - raise TestFailed("expected a RuntimeError") - def weakrefs(): if verbose: print("Testing weak references...") import weakref diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py index b9b2e6e..3d0d4aa 100644 --- a/Lib/test/test_funcattrs.py +++ b/Lib/test/test_funcattrs.py @@ -104,11 +104,12 @@ else: raise TestFailed if f2.a.one != f1.a.one != F.a.one != 11: raise TestFailed -# im_func may not be a Python method! +# __func__ may not be a Python method! import new -F.id = new.instancemethod(id, None, F) +F.id = id eff = F() +eff.id = new.instancemethod(id, eff) if eff.id() != id(eff): raise TestFailed @@ -296,32 +297,32 @@ def test_func_dict(): verify(f.__dict__ == {'world': 'hello'}) cantset(f, "__dict__", None) -def test_im_class(): +def test___self__(): class C: def foo(self): pass - #verify(C.foo.im_class is C) - verify(C().foo.im_class is C) - #cantset(C.foo, "im_class", C) - cantset(C().foo, "im_class", C) + #verify(C.foo.__self__.__class__ is C) + verify(C().foo.__self__.__class__ is C) + #cantset(C.foo, "__self__.__class__", C) + cantset(C().foo, "__self__.__class__", C) -def test_im_func(): +def test___func__(): def foo(self): pass class C: pass C.foo = foo - #verify(C.foo.im_func is foo) - verify(C().foo.im_func is foo) - #cantset(C.foo, "im_func", foo) - cantset(C().foo, "im_func", foo) + #verify(C.foo.__func__ is foo) + verify(C().foo.__func__ is foo) + #cantset(C.foo, "__func__", foo) + cantset(C().foo, "__func__", foo) -def test_im_self(): +def test___self__(): class C: def foo(self): pass - #verify(C.foo.im_self is None) + #verify(C.foo.__self__ is None) c = C() - #verify(c.foo.im_self is c) - #cantset(C.foo, "im_self", None) - #cantset(c.foo, "im_self", c) + #verify(c.foo.__self__ is c) + #cantset(C.foo, "__self__", None) + #cantset(c.foo, "__self__", c) def test_im_dict(): class C: @@ -358,9 +359,9 @@ def testmore(): test_func_defaults() test_func_dict() # Tests for instance method attributes - test_im_class() - test_im_func() - test_im_self() + test___self__() + test___func__() + test___self__() test_im_dict() test_im_doc() test_im_name() diff --git a/Lib/test/test_new.py b/Lib/test/test_new.py index 797a8c3..8e1d49d 100644 --- a/Lib/test/test_new.py +++ b/Lib/test/test_new.py @@ -25,7 +25,7 @@ class NewTest(unittest.TestCase): # new.instancemethod() c = C() c.yolks = 3 - im = new.instancemethod(break_yolks, c, C) + im = new.instancemethod(break_yolks, c) self.assertEqual(c.get_yolks(), 3, 'Broken call of hand-crafted class instance') @@ -43,7 +43,7 @@ class NewTest(unittest.TestCase): self.assertEqual(c.get_yolks(), -1) # Verify that dangerous instance method creation is forbidden - self.assertRaises(TypeError, new.instancemethod, break_yolks, None) + self.assertRaises(TypeError, new.instancemethod, None) # Verify that instancemethod() doesn't allow keyword args self.assertRaises(TypeError, new.instancemethod, break_yolks, c, kw=1) diff --git a/Lib/test/test_profilehooks.py b/Lib/test/test_profilehooks.py index 0f5616d..3a17dc7 100644 --- a/Lib/test/test_profilehooks.py +++ b/Lib/test/test_profilehooks.py @@ -31,7 +31,7 @@ class HookWatcher: def get_events(self): """Remove calls to add_event().""" - disallowed = [ident(self.add_event.im_func), ident(ident)] + disallowed = [ident(self.add_event.__func__), ident(ident)] self.frames = None return [item for item in self.events if item[2] not in disallowed] diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py index bcb7988..b88cb7e 100644 --- a/Lib/test/test_pyclbr.py +++ b/Lib/test/test_pyclbr.py @@ -67,7 +67,7 @@ class PyclbrTest(TestCase): if isinstance(obj, MethodType): # could be a classmethod if (not isinstance(classdict[name], ClassMethodType) or - obj.im_self is not oclass): + obj.__self__ is not oclass): return False elif not isinstance(obj, FunctionType): return False |