@@ -24,7 +24,7 @@ def append(self, item):
24
24
"Of course, you can still explicitly pass in the arguments if you want
25
25
to do something strange. Sometimes you really do want that, e.g. to
26
26
skip over some classes in the method resolution order.
27
-
27
+
28
28
"How does it work? By inspecting the calling frame to determine the
29
29
function object being executed and the object on which it's being
30
30
called, and then walking the object's __mro__ chain to find out where
@@ -51,14 +51,14 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1):
51
51
# Infer the correct call if used without arguments.
52
52
if typ is _SENTINEL :
53
53
# We'll need to do some frame hacking.
54
- f = sys ._getframe (framedepth )
54
+ f = sys ._getframe (framedepth )
55
55
56
56
try :
57
57
# Get the function's first positional argument.
58
58
type_or_obj = f .f_locals [f .f_code .co_varnames [0 ]]
59
59
except (IndexError , KeyError ,):
60
60
raise RuntimeError ('super() used in a function with no args' )
61
-
61
+
62
62
try :
63
63
# Get the MRO so we can crawl it.
64
64
mro = type_or_obj .__mro__
@@ -67,9 +67,9 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1):
67
67
mro = type_or_obj .__class__ .__mro__
68
68
except AttributeError :
69
69
raise RuntimeError ('super() used with a non-newstyle class' )
70
-
70
+
71
71
# A ``for...else`` block? Yes! It's odd, but useful.
72
- # If unfamiliar with for...else, see:
72
+ # If unfamiliar with for...else, see:
73
73
#
74
74
# http://psung.blogspot.com/2007/12/for-else-in-python.html
75
75
for typ in mro :
@@ -88,7 +88,7 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1):
88
88
try :
89
89
meth = meth .__func__
90
90
except AttributeError :
91
- meth = meth .__get__ (type_or_obj )
91
+ meth = meth .__get__ (type_or_obj , typ )
92
92
except (AttributeError , TypeError ):
93
93
continue
94
94
if meth .func_code is f .f_code :
@@ -98,7 +98,7 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1):
98
98
break # Found! Break out of the search loop.
99
99
else :
100
100
raise RuntimeError ('super() called outside a method' )
101
-
101
+
102
102
# Dispatch to builtin super().
103
103
if type_or_obj is not _SENTINEL :
104
104
return _builtin_super (typ , type_or_obj )
@@ -112,4 +112,3 @@ def superm(*args, **kwds):
112
112
113
113
114
114
__all__ = ['newsuper' ]
115
-
0 commit comments