[Patches] [ python-Patches-719777 ] Remove __file__ after running $PYTHONSTARTUP
SourceForge.net
noreply@sourceforge.net
Fri, 11 Apr 2003 09:25:19 -0700
Patches item #719777, was opened at 2003-04-11 12:25
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=719777&group_id=5470
Category: Core (C code)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 3
Submitted By: Fred L. Drake, Jr. (fdrake)
Assigned to: Neal Norwitz (nnorwitz)
Summary: Remove __file__ after running $PYTHONSTARTUP
Initial Comment:
When the file named by PYTHONSTARTUP is executed, an
__file__ is left behind in __main__ even though it
doesn't apply to commands run in the interactive
interpreter. This causes confusing output when
warnings are generated. For example, running CVS
Python with -Wall:
>>> raise 'foo'
/home/fdrake/env/python/INIT.py:1:
PendingDeprecationWarning: raising a string exception
is deprecated
# INIT.py
Traceback (most recent call last):
File "<stdin>", line 1, in ?
foo
Clearly, the deprecation warning is not generated
because of anything in the file named.
This patch causes the __file__ entry in the __main__
module to be removed after the PYTHONSTARTUP file has
been run. __file__ was not added to __main__ in Python
2.2; this is caused by a change to
PyRun_SimpleFileExFlags() in 2.3 (in particular, a
change I made so __file__ would be set while running
PYTHONSTARTUP). It does this simply by causing
PyRun_SimpleFileExFlags() to clean up after itself.
Functions defined in PYTHONSTARTUP that need __file__
after running will simply need to cache the value
somewhere (possibly just under a different name in
__main__'s globals).
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=719777&group_id=5470