[Patches] [ python-Patches-1644818 ] Allow importing built-in submodules

SourceForge.net noreply at sourceforge.net
Tue Mar 6 16:43:55 CET 2007


Patches item #1644818, was opened at 2007-01-25 23:12
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1644818&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core (C code)
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Miguel Lobo (mlobo)
Assigned to: Nobody/Anonymous (nobody)
Summary: Allow importing built-in submodules

Initial Comment:
At the moment importing built-in submodules (in my case PyQt4.QtCore and PyQt4.QtGui) does not work.  This seems to be because find_module in import.c checks only the module name (e.g. QtCore) against the built-in list, which should contain the full name (e.g. Python.QtCore) instead.

Also, the above check is performed after the code to check if the parent module is frozen, which would have already exited in that case.

By moving the is_builtin() check to earlier in find_module and using fullname instead of name, I can build PyQt4.QtCore and PyQt4.QtGui into the interpreter and import and use them with no problem whatsoever, even if their parent module (PyQt4) is frozen.

I have run the regression tests and everything seems Ok.

I am completely new to CPython development so it is quite possible that my solution is undesirable or that I have done something incorrectly.  Please let me know if that is the case.

Finally, the attached patch is for Python-2.5, but I have checked it also applies to current svn trunk with only a one-line offset.


----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2007-03-06 16:43

Message:
Logged In: YES 
user_id=21627
Originator: NO

Can you come up with a test case? Put the module in Modules/Setup, then
have a test case that tries importing it. The test case should check
whether the module is in builtin_module_names, and, if it is, try importing
it.

(Ideally, it should only make the module builtin if debug is enabled, but
I can't see how that can be achieved. Perhaps some trickery in config.c
could do that, and #ifdefing out the body of the module if debug is
disabled).

----------------------------------------------------------------------

Comment By: Collin Winter (collinwinter)
Date: 2007-03-06 01:23

Message:
Logged In: YES 
user_id=1344176
Originator: NO

This is the kind of thing you should bring up on the python-dev list
(http://mail.python.org/mailman/listinfo/python-dev). Please subscribe to
the list and send in a post with your problem and proposed solution. Thanks
for your effort!

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1644818&group_id=5470


More information about the Patches mailing list