Skip to content

Commit 7655484

Browse files
author
Grant Bakker
committed
Added type to __get__ call to prevent some c modules from segfaulting.
1 parent fe494df commit 7655484

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/future/builtins/newsuper.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def append(self, item):
2424
"Of course, you can still explicitly pass in the arguments if you want
2525
to do something strange. Sometimes you really do want that, e.g. to
2626
skip over some classes in the method resolution order.
27-
27+
2828
"How does it work? By inspecting the calling frame to determine the
2929
function object being executed and the object on which it's being
3030
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):
5151
# Infer the correct call if used without arguments.
5252
if typ is _SENTINEL:
5353
# We'll need to do some frame hacking.
54-
f = sys._getframe(framedepth)
54+
f = sys._getframe(framedepth)
5555

5656
try:
5757
# Get the function's first positional argument.
5858
type_or_obj = f.f_locals[f.f_code.co_varnames[0]]
5959
except (IndexError, KeyError,):
6060
raise RuntimeError('super() used in a function with no args')
61-
61+
6262
try:
6363
# Get the MRO so we can crawl it.
6464
mro = type_or_obj.__mro__
@@ -67,9 +67,9 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1):
6767
mro = type_or_obj.__class__.__mro__
6868
except AttributeError:
6969
raise RuntimeError('super() used with a non-newstyle class')
70-
70+
7171
# A ``for...else`` block? Yes! It's odd, but useful.
72-
# If unfamiliar with for...else, see:
72+
# If unfamiliar with for...else, see:
7373
#
7474
# http://psung.blogspot.com/2007/12/for-else-in-python.html
7575
for typ in mro:
@@ -88,7 +88,7 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1):
8888
try:
8989
meth = meth.__func__
9090
except AttributeError:
91-
meth = meth.__get__(type_or_obj)
91+
meth = meth.__get__(type_or_obj, typ)
9292
except (AttributeError, TypeError):
9393
continue
9494
if meth.func_code is f.f_code:
@@ -98,7 +98,7 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1):
9898
break # Found! Break out of the search loop.
9999
else:
100100
raise RuntimeError('super() called outside a method')
101-
101+
102102
# Dispatch to builtin super().
103103
if type_or_obj is not _SENTINEL:
104104
return _builtin_super(typ, type_or_obj)
@@ -112,4 +112,3 @@ def superm(*args, **kwds):
112112

113113

114114
__all__ = ['newsuper']
115-

0 commit comments

Comments
 (0)