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.

classification
Title: presence of .pythonstartup.py causes __main__.__file__ to be set incorrectly
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.4, Python 2.5
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, exarkun, loewis
Priority: normal Keywords:

Created on 2008-09-22 12:42 by exarkun, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
msg73572 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2008-09-22 12:42
exarkun@charm:~$ ls  .pythonstartup.py
.pythonstartup.py
exarkun@charm:~$ python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) 
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> __file__
'/home/exarkun/.pythonstartup.py'
>>> 
exarkun@charm:~$ mv .pythonstartup.py .not-pythonstartup.py
exarkun@charm:~$ python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) 
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> __file__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '__file__' is not defined
>>>
msg73573 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-22 13:03
Someone took the time machine and corrected this 18 months ago: r54189
is included in the 2.6 version.
msg73574 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2008-09-22 13:11
Why wasn't it backported to 2.5?
msg73577 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-22 13:48
I was not there, but the usual rules state that a backport is not
allowed to break working code, even if it relies on undocumented
features or side-effects.

Here, PyRun_SimpleFileExFlags changed its behaviour: it now deletes
__main__.__file__ and some applications may have used this attribute in
some way.
msg73578 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2008-09-22 13:57
Any buggy behavior might be relied on by applications.  Taken to the
extreme, you can never have a bug-fix release of Python.

__file__ from PYTHONSTARTUP breaks the warnings module.  It would be
difficult for an application to rely on __main__.__file__ being set,
since $PYTHONSTARTUP is only read in interactive mode - when it's a
human using Python, not a program.  Of course another process could run
Python interactively in a child process and then rely on __file__, sure.
 But why is that valid?  It's not like __file__ *means* something there
- it's just the value of PYTHONSTARTUP.

But I guess I don't really care anymore.  I understand why warnings are
being reported incorrectly now, so I doubt this affects /me/ anymore. 
It seems like it'd be better to reduce confusion for other people too,
but that's not up to me.

Thanks for pointing out where it was fixed in 2.6.
msg73579 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-22 14:06
I was thinking about an application that embeds an interpreter, and
calls PyRun_SimpleFile(). There are many ways to use python...
msg73597 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-09-22 21:13
Jean-Paul, to find out why the specific patch was not backported, you
would have to ask the original committer (which happens to be Georg
Brandl). If you want to ask that question through the tracker, it's best
to add him to the nosy list, so that he can actually see that he is
being asked a question.

My guess is as good as everybody else's: most likely, he didn't have the
time to backport, or didn't consider it important enough.
History
Date User Action Args
2022-04-11 14:56:39adminsetgithub: 48183
2008-09-22 21:13:11loewissetnosy: + loewis
messages: + msg73597
2008-09-22 14:06:22amaury.forgeotdarcsetmessages: + msg73579
2008-09-22 13:57:16exarkunsetmessages: + msg73578
2008-09-22 13:48:08amaury.forgeotdarcsetmessages: + msg73577
2008-09-22 13:11:43exarkunsetmessages: + msg73574
2008-09-22 13:03:31amaury.forgeotdarcsetstatus: open -> closed
resolution: out of date
messages: + msg73573
nosy: + amaury.forgeotdarc
2008-09-22 12:42:57exarkuncreate