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.

Title: Remove __file__ after running $PYTHONSTARTUP
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: fdrake, nnorwitz
Priority: low Keywords: patch

Created on 2003-04-11 16:25 by fdrake, last changed 2022-04-10 16:08 by admin. This issue is now closed.

File name Uploaded Description Edit
startup.diff fdrake, 2003-04-11 16:25 remove __file__ caused by running PYTHONSTARTUP
Messages (2)
msg43326 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2003-04-11 16:25
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'
PendingDeprecationWarning: raising a string exception
is deprecated
Traceback (most recent call last):
  File "<stdin>", line 1, in ?

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).
msg43327 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2004-10-21 03:01
Logged In: YES 

Duplicate of 703779.  Fred are you still interested in this
patch?  Should we try to get it in 2.4?
Date User Action Args
2022-04-10 16:08:06adminsetgithub: 38291
2003-04-11 16:25:19fdrakecreate