using sys._getframe(x), where x > 0 doesnt' work on IronPython

This commit is contained in:
Benjamin Peterson 2009-05-05 00:55:24 +00:00
parent 7ba8e1cbfd
commit 7c67b03051
1 changed files with 5 additions and 2 deletions

View File

@ -268,9 +268,12 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
# For pickling to work, the __module__ variable needs to be set to the frame
# where the named tuple is created. Bypass this step in enviroments where
# sys._getframe is not defined (Jython for example).
if hasattr(_sys, '_getframe'):
# sys._getframe is not defined (Jython for example) or sys._getframe is not
# defined for arguments greater than 0 (IronPython).
try:
result.__module__ = _sys._getframe(1).f_globals.get('__name__', '__main__')
except (AttributeError, ValueError):
pass
return result