Re: [Python-Dev] [Python-checkins] r83890 - python/branches/py3k/Lib/inspect.py

On Mon, Aug 9, 2010 at 11:05 PM, benjamin.peterson <python-checkins@python.org> wrote:
-if hasattr(sys, '_getframe'): - currentframe = sys._getframe -else: - currentframe = lambda _=None: None +def currentframe(): + """Return the frame or the caller or None if this is not possible.""" + return sys._getframe(1) if hasattr(sys, "_getframe") else None
It isn't hugely important, but with sys._getframe() unlikely to appear during runtime, the following may make more sense: if hasattr(sys, '_getframe'): def currentframe(): return sys._getframe(1) else: def currentframe(): pass currentframe.__doc__ = "Return the frame of the caller or None if this is not possible." (Oh, and there's a typo in the docstring...) Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

2010/8/9 Nick Coghlan <ncoghlan@gmail.com>:
On Mon, Aug 9, 2010 at 11:05 PM, benjamin.peterson <python-checkins@python.org> wrote:
-if hasattr(sys, '_getframe'): - currentframe = sys._getframe -else: - currentframe = lambda _=None: None +def currentframe(): + """Return the frame or the caller or None if this is not possible.""" + return sys._getframe(1) if hasattr(sys, "_getframe") else None
It isn't hugely important, but with sys._getframe() unlikely to appear during runtime, the following may make more sense:
if hasattr(sys, '_getframe'): def currentframe(): return sys._getframe(1) else: def currentframe(): pass currentframe.__doc__ = "Return the frame of the caller or None if this is not possible."
I considered that but found the docstring thing ugly.
(Oh, and there's a typo in the docstring...)
Thanks. -- Regards, Benjamin

On Mon, Aug 9, 2010 at 11:48 AM, Benjamin Peterson <benjamin@python.org> wrote:
2010/8/9 Nick Coghlan <ncoghlan@gmail.com>:
On Mon, Aug 9, 2010 at 11:05 PM, benjamin.peterson <python-checkins@python.org> wrote:
-if hasattr(sys, '_getframe'): - currentframe = sys._getframe -else: - currentframe = lambda _=None: None +def currentframe(): + """Return the frame or the caller or None if this is not possible.""" + return sys._getframe(1) if hasattr(sys, "_getframe") else None
It isn't hugely important, but with sys._getframe() unlikely to appear during runtime, the following may make more sense:
if hasattr(sys, '_getframe'): def currentframe(): return sys._getframe(1) else: def currentframe(): pass currentframe.__doc__ = "Return the frame of the caller or None if this is not possible."
I considered that but found the docstring thing ugly.
I think I have a brighter color for this bikeshed: if hasattr(sys, '_getframe'): def currentframe(): "Return the frame of the caller." .. else: def currentframe(): "Not supported on this platform. Always returns None." .. The working version's docstring may also explain that it may return None on some platforms.
participants (3)
-
Alexander Belopolsky
-
Benjamin Peterson
-
Nick Coghlan