
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2017-04-26 08:53 byanjos, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 6731 | merged | steverweber,2018-05-09 12:19 | |
| PR 7415 | merged | methane,2018-06-05 07:25 | |
| PR 7606 | merged | miss-islington,2018-06-11 00:50 | |
| PR 7607 | merged | miss-islington,2018-06-11 00:51 | |
| PR 7617 | merged | methane,2018-06-11 05:52 | |
| Messages (11) | |||
|---|---|---|---|
| msg292325 -(view) | Author: André Anjos (anjos) | Date: 2017-04-26 08:53 | |
Apparently, "import site; site.main()" does not seem to work anymore on Python 3.6 and superior.The reason is a change on the behavior of "os.path.abspath(None)". Before Python 3.6, it used to report an AttributeError which is properly caught inside "site.abs_paths" (see:https://github.com/python/cpython/blob/master/Lib/site.py#L99), making it ignore __main__, one of sys.modules, which has __file__ and __cached__ set to None.With Python 3.6 and superior, os.path.abspath(None) reports a TypeError, which makes calling "site.main()" raise an exception and stop.How to reproduce: On python 3.6 or superior, do "import site; site.main()".Expected behavior: Exception is properly caught and treated inside "site.abs_paths", ignoring modules in which __file__ and/or __cached__ are set to None. | |||
| msg292327 -(view) | Author: André Anjos (anjos) | Date: 2017-04-26 09:13 | |
More information: to reproduce the problem, don't use Python's "-c" command-line option. In this case "__main__" won't be inside sys.modules which mitigates the issue. | |||
| msg292329 -(view) | Author: André Anjos (anjos) | Date: 2017-04-26 09:55 | |
After further investigation, the issue can only be reproduced iff the user sets PYTHONSTARTUP which triggers "__main__" to appear in sys.modules and the problem to occur. | |||
| msg316295 -(view) | Author: steverweber (steverweber)* | Date: 2018-05-08 19:19 | |
ref to other projects that hit this issue.https://gitlab.idiap.ch/bob/bob.buildout/issues/15https://github.com/saltstack/salt/issues/45080https://groups.google.com/forum/#!msg/comp.lang.python/tpfiHAJhl9Y/hZj1f50vBQAJ | |||
| msg318725 -(view) | Author: Inada Naoki (methane)*![]() | Date: 2018-06-05 06:21 | |
https://github.com/python/cpython/blob/f822549653d8d09bffff5b7dcddfdf12679a787c/Python/pythonrun.c#L391-L399__file__ and __cached__ are added here. And,https://github.com/python/cpython/blob/f822549653d8d09bffff5b7dcddfdf12679a787c/Python/pythonrun.c#L441-L442Only __file__ is removed here. I feel __cached__ should be removed too.On the other hand, if None is valid value for __cached__, site.abs_paths() should ignore it.https://www.python.org/dev/peps/pep-3147/#file> It is recommended that when nothing sensible can be calculated, implementations should set the __cached__ attribute to None.It seems it's valid, and recommended for some cases. SoPR-6731 looks OK. | |||
| msg319258 -(view) | Author: Ned Deily (ned.deily)*![]() | Date: 2018-06-11 00:49 | |
New changeset2487f30d5529948ace26559e274d7cac6abcd1a8 by Ned Deily (Steve Weber) in branch 'master':bpo-30167: Prevent site.main() exception if PYTHONSTARTUP is set. (GH-6731)https://github.com/python/cpython/commit/2487f30d5529948ace26559e274d7cac6abcd1a8 | |||
| msg319260 -(view) | Author: Ned Deily (ned.deily)*![]() | Date: 2018-06-11 01:21 | |
New changesetec4343c3b4c0e0a7500122fac616e6488c0ab842 by Ned Deily (Miss Islington (bot)) in branch '3.7':bpo-30167: Prevent site.main() exception if PYTHONSTARTUP is set. (GH-6731) (GH-7606)https://github.com/python/cpython/commit/ec4343c3b4c0e0a7500122fac616e6488c0ab842 | |||
| msg319261 -(view) | Author: Ned Deily (ned.deily)*![]() | Date: 2018-06-11 01:23 | |
New changeset3e121581d008a780b8a9f1bcda5966cf0c06f6d5 by Ned Deily (Miss Islington (bot)) in branch '3.6':bpo-30167: Prevent site.main() exception if PYTHONSTARTUP is set. (GH-6731) (GH-7607)https://github.com/python/cpython/commit/3e121581d008a780b8a9f1bcda5966cf0c06f6d5 | |||
| msg319262 -(view) | Author: Ned Deily (ned.deily)*![]() | Date: 2018-06-11 01:30 | |
As I noted in the discussion onPR 6731, I think there should be a test for this so we don't break it again. But, since it seems that the problem has affected a number of users and projects and since the fix is easy and easily testable manually, I decided to merge the PR for 3.7.0rc1 and 3.6.6rc1. I am leaving the issue open for someone to supply a PR with a test case and for discussion ofPR 7415. Thank you all! | |||
| msg326797 -(view) | Author: Inada Naoki (methane)*![]() | Date: 2018-10-01 12:10 | |
New changesetd4c76d960b8b286b75c933780416ace9cda682fd by INADA Naoki in branch 'master':bpo-30167: Add test for module.__cached__ is None (GH-7617)https://github.com/python/cpython/commit/d4c76d960b8b286b75c933780416ace9cda682fd | |||
| msg330677 -(view) | Author: Inada Naoki (methane)*![]() | Date: 2018-11-29 11:01 | |
New changeset82daa60defbd6497efdaa6c1132ecc8563122ed5 by INADA Naoki in branch 'master':bpo-30167: Remove __cached__ from __main__ when removing __file__ (GH-7415)https://github.com/python/cpython/commit/82daa60defbd6497efdaa6c1132ecc8563122ed5 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:45 | admin | set | github: 74353 |
| 2018-11-30 11:32:45 | methane | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2018-11-29 11:01:32 | methane | set | messages: +msg330677 |
| 2018-10-01 12:10:45 | methane | set | messages: +msg326797 |
| 2018-06-11 05:52:17 | methane | set | stage: needs patch -> patch review pull_requests: +pull_request7238 |
| 2018-06-11 01:30:15 | ned.deily | set | stage: patch review -> needs patch messages: +msg319262 versions: + Python 3.8 |
| 2018-06-11 01:23:43 | ned.deily | set | messages: +msg319261 |
| 2018-06-11 01:21:37 | ned.deily | set | messages: +msg319260 |
| 2018-06-11 00:51:44 | miss-islington | set | pull_requests: +pull_request7230 |
| 2018-06-11 00:50:49 | miss-islington | set | pull_requests: +pull_request7229 |
| 2018-06-11 00:49:37 | ned.deily | set | nosy: +ned.deily messages: +msg319258 |
| 2018-06-05 07:25:04 | methane | set | pull_requests: +pull_request7039 |
| 2018-06-05 06:21:02 | methane | set | nosy: +methane messages: +msg318725 |
| 2018-05-09 12:19:35 | steverweber | set | keywords: +patch stage: patch review pull_requests: +pull_request6432 |
| 2018-05-08 19:19:40 | steverweber | set | nosy: +steverweber messages: +msg316295 |
| 2017-04-26 17:05:32 | anjos | set | title: site.main() does not work on Python 3.6 and superior with PYTHONSTARTUP is set -> site.main() does not work on Python 3.6 and superior if PYTHONSTARTUP is set |
| 2017-04-26 17:05:18 | anjos | set | title: site.main() does not work on Python 3.6 and superior -> site.main() does not work on Python 3.6 and superior with PYTHONSTARTUP is set |
| 2017-04-26 09:55:28 | anjos | set | messages: +msg292329 |
| 2017-04-26 09:13:10 | anjos | set | messages: +msg292327 |
| 2017-04-26 08:53:33 | anjos | create | |