homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Benjamin.S.Wolf, eric.araujo, ncoghlan
Date 2012年07月07日.10:47:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1341658065.35.0.602404575235.issue15230@psf.upfronthosting.co.za>
In-reply-to
Content
Firstly, I think you've identified a real bug with __package__ not being set correctly when using runpy.run_path (and I have updated this issue title accordingly).
I have also created a separate bug report (#15272) for the bizarre behaviour you identified in runpy.run_module - names containing "/" characters should be rejected as invalid. 
One of the main reasons you're having trouble though is that you can only do relative imports when inside a package - at the top level (as both of your modules are) relative imports are illegal. By forcing package to "__main__" you are claiming a location in the package namespace of "__main__.__main__" which doesn't make any sense.
The module life cycle problem for functions is covered in #812369. The only reason you're not hitting it in the run_module case is that when "alter_sys" is False, no temporary module is created. For data attributes (the intended use case for runpy), this all works fine regardless, but functions (which retain a reference to the original module namespace) will only work properly with alter_sys turned off. There should probably be a general disclaimer in the module docs that functions and classes are not guaranteed to be valid after using runpy, and importlib.import_module should be used instead for such cases.
#9235 looks into ways the runpy module might be enhanced with a CodeRunner class for other reasons, but the same mechanism could be used to keep the temporary module alive without storing it in sys.modules.
History
Date User Action Args
2012年07月07日 10:47:45ncoghlansetrecipients: + ncoghlan, eric.araujo, Benjamin.S.Wolf
2012年07月07日 10:47:45ncoghlansetmessageid: <1341658065.35.0.602404575235.issue15230@psf.upfronthosting.co.za>
2012年07月07日 10:47:44ncoghlanlinkissue15230 messages
2012年07月07日 10:47:44ncoghlancreate

AltStyle によって変換されたページ (->オリジナル) /