classification
Title: sys._getframe is not available on all Python implementations
Type: Stage:
Components: Documentation Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: brett.cannon, cvrebert, georg.brandl, gregory.p.smith, johannes.janssen, michael.foord, thobe
Priority: normal Keywords:

Created on 2009-08-16 10:44 by johannes.janssen, last changed 2009-09-13 16:46 by michael.foord. This issue is now closed.

Messages (9)
msg91629 - (view) Author: Johannes Janssen (johannes.janssen) Date: 2009-08-16 10:44
As I learned on the mailing list the function sys._getframe() is not
available on all Python implementations (e.g. jython). This information
should be added to the documentation.
msg91641 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2009-08-16 18:55
The leading underscore is meant to convey that it is not guaranteed to 
exist. But in spite of this, we do plan long-term to make it explicit what 
all interpreters are expected to (not) support.
msg91647 - (view) Author: Tobias Ivarsson (thobe) * Date: 2009-08-16 22:01
While it is true that not all Python implementations support
sys._getframe() in some or all execution modes, Jython does support it,
even IronPython supports it with the proper startup parameters these days.

More importantly sys._getframe() [or something equivalent] *is*
available as a public API in the inspect module of Python, as
inspect.currentframe(). I don't know why the inspect module is not
brought up in the discussions about sys._getframe(), but it is a public
API. Would this mean that introspecting callframes is something all
interpreters are expected to support? Brett: what is your opinion?
Perhaps I should move this discussion to the mailing list?
msg91648 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2009-08-16 22:11
Yeah I'd take this to the list.  Perhaps this is destined to be a public
API.
msg91649 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-08-16 22:24
It's actually quite annoying that inspect takes a private API (that has
warnings in the documentation about its use) and makes it public. It's
just a direct alias. That in itself is not a good reason to say the
_getframe should be public.

Python frames are not available by *default* in Python, because of the
performance cost of using them.
msg91651 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2009-08-16 23:16
It sounds like inspect needs to have its docs updated such that it makes 
it explicit inspect.currentframe() requires sys._getframe() to exist to 
return anything of use (the code returns None in other cases). So the 
public API can exist, but it needs to say what it depends on is optional.
msg91652 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-08-16 23:23
I meant in IronPython of course. D'oh. Anyway, I made the change to
inspect to keep it compatible with IronPython so I can make the
documentation change.

A mention in the sys._getframe docs that it is not guaranteed to exist
across implementations would be useful. I'll add that unless there are
major objections.
msg91653 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2009-08-16 23:34
On Sun, Aug 16, 2009 at 16:23, Michael Foord<report@bugs.python.org> wrote:
>
> Michael Foord <michael@voidspace.org.uk> added the comment:
>
> I meant in IronPython of course. D'oh. Anyway, I made the change to
> inspect to keep it compatible with IronPython so I can make the
> documentation change.
>
> A mention in the sys._getframe docs that it is not guaranteed to exist
> across implementations would be useful. I'll add that unless there are
> major objections.

You won't get objections as that's what the code does. I say just do
it and if people actually object we can back out the commit.
msg92572 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-09-13 16:46
Committed revision 74781.
History
Date User Action Args
2009-09-13 16:46:42michael.foordsetstatus: open -> closed
resolution: accepted
messages: + msg92572
2009-08-16 23:34:02brett.cannonsetmessages: + msg91653
2009-08-16 23:23:06michael.foordsetmessages: + msg91652
2009-08-16 23:16:48brett.cannonsetmessages: + msg91651
2009-08-16 22:24:23michael.foordsetnosy: + michael.foord
messages: + msg91649
2009-08-16 22:11:05gregory.p.smithsetnosy: + gregory.p.smith
messages: + msg91648
2009-08-16 22:01:29thobesetnosy: + thobe
messages: + msg91647
2009-08-16 18:55:01brett.cannonsetnosy: + brett.cannon
messages: + msg91641
2009-08-16 11:12:55cvrebertsetnosy: + cvrebert
2009-08-16 10:44:19johannes.janssencreate