[Python-Dev] [Python-checkins] r83890 - python/branches/py3k/Lib/inspect.py (original) (raw)
Alexander Belopolsky alexander.belopolsky at gmail.com
Mon Aug 9 18:26:46 CEST 2010
- Previous message: [Python-Dev] [Python-checkins] r83890 - python/branches/py3k/Lib/inspect.py
- Next message: [Python-Dev] [Python-checkins] r83893 - python/branches/release27-maint/Misc/ACKS
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Aug 9, 2010 at 11:48 AM, Benjamin Peterson <benjamin at python.org> wrote:
2010/8/9 Nick Coghlan <ncoghlan at gmail.com>:
On Mon, Aug 9, 2010 at 11:05 PM, benjamin.peterson <python-checkins at 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.
- Previous message: [Python-Dev] [Python-checkins] r83890 - python/branches/py3k/Lib/inspect.py
- Next message: [Python-Dev] [Python-checkins] r83893 - python/branches/release27-maint/Misc/ACKS
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]