summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/ctypes/test/test_callbacks.py8
-rw-r--r--Lib/dis.py4
-rw-r--r--Lib/doctest.py4
-rw-r--r--Lib/idlelib/CallTips.py6
-rw-r--r--Lib/inspect.py13
-rw-r--r--Lib/lib-tk/Tkinter.py2
-rwxr-xr-xLib/pdb.py6
-rwxr-xr-xLib/pydoc.py16
-rw-r--r--Lib/test/crashers/borrowed_ref_2.py2
-rw-r--r--Lib/test/test_descr.py31
-rw-r--r--Lib/test/test_funcattrs.py41
-rw-r--r--Lib/test/test_new.py4
-rw-r--r--Lib/test/test_profilehooks.py2
-rw-r--r--Lib/test/test_pyclbr.py2
14 files changed, 65 insertions, 76 deletions
diff --git a/Lib/ctypes/test/test_callbacks.py b/Lib/ctypes/test/test_callbacks.py
index d870eb4..bf580ae 100644
--- a/Lib/ctypes/test/test_callbacks.py
+++ b/Lib/ctypes/test/test_callbacks.py
@@ -14,7 +14,7 @@ class Callbacks(unittest.TestCase):
return args[-1]
def check_type(self, typ, arg):
- PROTO = self.functype.im_func(typ, typ)
+ PROTO = self.functype.__func__(typ, typ)
result = PROTO(self.callback)(arg)
if typ == c_float:
self.failUnlessAlmostEqual(result, arg, places=5)
@@ -22,7 +22,7 @@ class Callbacks(unittest.TestCase):
self.failUnlessEqual(self.got_args, (arg,))
self.failUnlessEqual(result, arg)
- PROTO = self.functype.im_func(typ, c_byte, typ)
+ PROTO = self.functype.__func__(typ, c_byte, typ)
result = PROTO(self.callback)(-3, arg)
if typ == c_float:
self.failUnlessAlmostEqual(result, arg, places=5)
@@ -110,12 +110,12 @@ class Callbacks(unittest.TestCase):
# functions, the type must have a non-NULL stgdict->setfunc.
# POINTER(c_double), for example, is not supported.
- prototype = self.functype.im_func(POINTER(c_double))
+ prototype = self.functype.__func__(POINTER(c_double))
# The type is checked when the prototype is called
self.assertRaises(TypeError, prototype, lambda: None)
def test_unsupported_restype_2(self):
- prototype = self.functype.im_func(object)
+ prototype = self.functype.__func__(object)
self.assertRaises(TypeError, prototype, lambda: None)
try:
diff --git a/Lib/dis.py b/Lib/dis.py
index 4cf452a..6d52694 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -18,8 +18,8 @@ def dis(x=None):
if x is None:
distb()
return
- if hasattr(x, 'im_func'):
- x = x.im_func
+ if hasattr(x, '__func__'):
+ x = x.__func__
if hasattr(x, '__code__'):
x = x.__code__
if hasattr(x, '__dict__'):
diff --git a/Lib/doctest.py b/Lib/doctest.py
index 5b18073..f135027 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -913,7 +913,7 @@ class DocTestFinder:
if isinstance(val, staticmethod):
val = getattr(obj, valname)
if isinstance(val, classmethod):
- val = getattr(obj, valname).im_func
+ val = getattr(obj, valname).__func__
# Recurse to methods, properties, and nested classes.
if ((inspect.isfunction(val) or inspect.isclass(val) or
@@ -985,7 +985,7 @@ class DocTestFinder:
break
# Find the line number for functions & methods.
- if inspect.ismethod(obj): obj = obj.im_func
+ if inspect.ismethod(obj): obj = obj.__func__
if inspect.isfunction(obj): obj = obj.__code__
if inspect.istraceback(obj): obj = obj.tb_frame
if inspect.isframe(obj): obj = obj.f_code
diff --git a/Lib/idlelib/CallTips.py b/Lib/idlelib/CallTips.py
index aee7e61..cda2be9 100644
--- a/Lib/idlelib/CallTips.py
+++ b/Lib/idlelib/CallTips.py
@@ -116,7 +116,7 @@ class CallTips:
def _find_constructor(class_ob):
"Find the nearest __init__() in the class tree."
try:
- return class_ob.__init__.im_func
+ return class_ob.__init__.__func__
except AttributeError:
for base in class_ob.__bases__:
init = _find_constructor(base)
@@ -133,7 +133,7 @@ def get_argspec(ob):
if fob is None:
fob = lambda: None
elif isinstance(ob, types.MethodType):
- fob = ob.im_func
+ fob = ob.__func__
else:
fob = ob
if isinstance(fob, (types.FunctionType, types.LambdaType)):
@@ -183,7 +183,7 @@ def main():
name = t.__name__
# exercise fetch_tip(), not just get_argspec()
try:
- qualified_name = "%s.%s" % (t.im_class.__name__, name)
+ qualified_name = "%s.%s" % (t.__self__.__class__.__name__, name)
except AttributeError:
qualified_name = name
argspec = ct.fetch_tip(qualified_name)
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 3a95796..a1910e4 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -55,9 +55,8 @@ def ismethod(object):
Instance method objects provide these attributes:
__doc__ documentation string
__name__ name with which this method was defined
- im_class class object in which this method belongs
- im_func function object containing implementation of method
- im_self instance to which this method is bound"""
+ __func__ function object containing implementation of method
+ __self__ instance to which this method is bound"""
return isinstance(object, types.MethodType)
def ismethoddescriptor(object):
@@ -73,7 +72,7 @@ def ismethoddescriptor(object):
Methods implemented via descriptors that also pass one of the other
tests return false from the ismethoddescriptor() test, simply because
the other tests promise more -- you can, e.g., count on having the
- im_func attribute (etc) when an object passes ismethod()."""
+ __func__ attribute (etc) when an object passes ismethod()."""
return (hasattr(object, "__get__")
and not hasattr(object, "__set__") # else it's a data descriptor
and not ismethod(object) # mutual exclusion
@@ -351,7 +350,7 @@ def getfile(object):
return object.__file__
raise TypeError('arg is a built-in class')
if ismethod(object):
- object = object.im_func
+ object = object.__func__
if isfunction(object):
object = object.__code__
if istraceback(object):
@@ -494,7 +493,7 @@ def findsource(object):
raise IOError('could not find class definition')
if ismethod(object):
- object = object.im_func
+ object = object.__func__
if isfunction(object):
object = object.__code__
if istraceback(object):
@@ -744,7 +743,7 @@ def getfullargspec(func):
"""
if ismethod(func):
- func = func.im_func
+ func = func.__func__
if not isfunction(func):
raise TypeError('arg is not a Python function')
args, varargs, kwonlyargs, varkw = _getfullargs(func.__code__)
diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py
index f40a553..aecb317 100644
--- a/Lib/lib-tk/Tkinter.py
+++ b/Lib/lib-tk/Tkinter.py
@@ -1081,7 +1081,7 @@ class Misc:
f = CallWrapper(func, subst, self).__call__
name = repr(id(f))
try:
- func = func.im_func
+ func = func.__func__
except AttributeError:
pass
try:
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 3d79b4d..f5bdb20 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -345,8 +345,8 @@ class Pdb(bdb.Bdb, cmd.Cmd):
except:
func = arg
try:
- if hasattr(func, 'im_func'):
- func = func.im_func
+ if hasattr(func, '__func__'):
+ func = func.__func__
code = func.__code__
#use co_name to identify the bkpt (function names
#could be aliased, but co_name is invariant)
@@ -789,7 +789,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
print('Function', code.co_name, file=self.stdout)
return
# Is it an instance method?
- try: code = value.im_func.__code__
+ try: code = value.__func__.__code__
except: pass
if code:
print('Method', code.co_name, file=self.stdout)
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 3cffa06..51d627e 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -848,17 +848,17 @@ class HTMLDoc(Doc):
note = ''
skipdocs = 0
if inspect.ismethod(object):
- imclass = object.im_class
+ imclass = object.__self__.__class__
if cl:
if imclass is not cl:
note = ' from ' + self.classlink(imclass, mod)
else:
- if object.im_self is not None:
+ if object.__self__ is not None:
note = ' method of %s instance' % self.classlink(
- object.im_self.__class__, mod)
+ object.__self__.__class__, mod)
else:
note = ' unbound %s method' % self.classlink(imclass,mod)
- object = object.im_func
+ object = object.__func__
if name == realname:
title = '<a name="%s"><strong>%s</strong></a>' % (anchor, realname)
@@ -1227,17 +1227,17 @@ class TextDoc(Doc):
note = ''
skipdocs = 0
if inspect.ismethod(object):
- imclass = object.im_class
+ imclass = object.__self__.__class__
if cl:
if imclass is not cl:
note = ' from ' + classname(imclass, mod)
else:
- if object.im_self is not None:
+ if object.__self__ is not None:
note = ' method of %s instance' % classname(
- object.im_self.__class__, mod)
+ object.__self__.__class__, mod)
else:
note = ' unbound %s method' % classname(imclass,mod)
- object = object.im_func
+ object = object.__func__
if name == realname:
title = self.bold(realname)
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