467,864 Members | 1,893 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,864 developers. It's quick & easy.

How to tell the parent frame is a C module? (Lazy importing)

Hello all,
I've been working on a lazy import module to be found here:
http://aspn.activestate.com/ASPN/Coo.../Recipe/473888

The basic idea is that a module proxy for foo is returned from an
'import foo' statement. When an attribute of foo is accessed, or
dir(foo) is called, or a from foo import * is done, the module is
actually loaded, and the module proxy is replaced in the calling
frame. This relies on the proxy being able to intercept __getattr__,
etc from the module and behaving appropriately.

This seems to work very well except in the case where the importing
module is a C module.

When getting the attributes of a class in C, python does the following check:

if (!PyModule_Check(m)) {
PyErr_BadInternalCall();
return NULL;
}
d = ((PyModuleObject *)m) -> md_dict;

Which does an end-run around all of my module-related evilness.

I'm hoping that there is some way to somehow detect when the import
statement is being called from a C module, and in that case just load
the module normally. But I can't figure out any way to detect that
from python. In fact, in sys.frame it looks like any C modules are
simply skipped over. I could try to detect that an intermdiate frame
is missing, I suppose....

Any pointers?
Dave
Feb 15 '06 #1
  • viewed: 755
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Stuart Wexler | last post: by
2 posts views Thread by Amadelle | last post: by
3 posts views Thread by Zachary Pincus | last post: by
5 posts views Thread by dg.google.groups | last post: by
1 post views Thread by Ryan Krauss | last post: by
1 post views Thread by michal.podlewski | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.