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 fdrake
Recipients
Date 2003-04-11.16:25:19
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
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).
History
Date User Action Args
2007-08-23 15:22:09adminlinkissue719777 messages
2007-08-23 15:22:09admincreate