Skip to content

Added type to __get__ call to prevent some c modules from segfaulting. #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/future/builtins/newsuper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def append(self, item):
"Of course, you can still explicitly pass in the arguments if you want
to do something strange. Sometimes you really do want that, e.g. to
skip over some classes in the method resolution order.

"How does it work? By inspecting the calling frame to determine the
function object being executed and the object on which it's being
called, and then walking the object's __mro__ chain to find out where
Expand All @@ -51,14 +51,14 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1):
# Infer the correct call if used without arguments.
if typ is _SENTINEL:
# We'll need to do some frame hacking.
f = sys._getframe(framedepth)
f = sys._getframe(framedepth)

try:
# Get the function's first positional argument.
type_or_obj = f.f_locals[f.f_code.co_varnames[0]]
except (IndexError, KeyError,):
raise RuntimeError('super() used in a function with no args')

try:
# Get the MRO so we can crawl it.
mro = type_or_obj.__mro__
Expand All @@ -67,9 +67,9 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1):
mro = type_or_obj.__class__.__mro__
except AttributeError:
raise RuntimeError('super() used with a non-newstyle class')

# A ``for...else`` block? Yes! It's odd, but useful.
# If unfamiliar with for...else, see:
# If unfamiliar with for...else, see:
#
# http://psung.blogspot.com/2007/12/for-else-in-python.html
for typ in mro:
Expand All @@ -88,7 +88,7 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1):
try:
meth = meth.__func__
except AttributeError:
meth = meth.__get__(type_or_obj)
meth = meth.__get__(type_or_obj, typ)
except (AttributeError, TypeError):
continue
if meth.func_code is f.f_code:
Expand All @@ -98,7 +98,7 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1):
break # Found! Break out of the search loop.
else:
raise RuntimeError('super() called outside a method')

# Dispatch to builtin super().
if type_or_obj is not _SENTINEL:
return _builtin_super(typ, type_or_obj)
Expand All @@ -112,4 +112,3 @@ def superm(*args, **kwds):


__all__ = ['newsuper']