classification
Title: Incorrect logging in importlib when '.pyc' file creation fails
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, eric.snow, iritkatriel, miss-islington, ncoghlan, pablogsal, qagren, xtreak
Priority: normal Keywords: patch

Created on 2018-10-19 04:00 by qagren, last changed 2020-08-18 18:42 by brett.cannon. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 9998 merged qagren, 2018-10-20 05:45
Messages (4)
msg328029 - (view) Author: Quentin Agren (qagren) * Date: 2018-10-19 04:00
Hi,

This is the first issue I submit so please correct me if I do anything wrong. 

Description of the issue:
imporlib logs 'wrote <path to .pyc file>' even when file creation fails with OSError (for lack of write persmission for example) 

Reproducing the bug in Python 3.6 on ubuntu 16.04:

cd /home/quentin/tmp
mkdir __pycache__
chmod -R -w __pycache__
echo '1 + 1' > spam.py
python -vv -c'import spam' 2>&1 | grep '__pycache__/spam'

Output:
# could not create '/home/quentin/tmp/__pycache__/spam.cpython-36.pyc': PermissionError(13, 'Permission denied')
# wrote '/home/quentin/tmp/__pycache__/spam.cpython-36.pyc'


Reason:
SourceFileLoader.set_data() silences OSError raised by _write_atomic (importlib/_bootstrap_external.py line 875) 
Then SourceLoader.get_code() does not see that something went awry and logs file creation (same file, line 789) 


If it is worth fixing I would be glad to contribute a patch, but would probably need a little guidance.
msg328586 - (view) Author: miss-islington (miss-islington) Date: 2018-10-26 18:36
New changeset 9e14e49f13ef1a726f31efe6689285463332db6e by Miss Islington (bot) (Quentin Agren) in branch 'master':
bpo-35024: Remove redundant and possibly incorrect verbose message after writing '.pyc' (GH-9998)
https://github.com/python/cpython/commit/9e14e49f13ef1a726f31efe6689285463332db6e
msg375569 - (view) Author: Irit Katriel (iritkatriel) * (Python triager) Date: 2020-08-17 21:58
This seems resolved, can it be closed?
msg375624 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-08-18 18:42
It looks like it! Thanks, Irit!
History
Date User Action Args
2020-08-18 18:42:10brett.cannonsetstatus: open -> closed
resolution: fixed
messages: + msg375624

stage: patch review -> resolved
2020-08-17 21:58:55iritkatrielsetnosy: + iritkatriel
messages: + msg375569
2018-10-26 18:36:36miss-islingtonsetnosy: + miss-islington
messages: + msg328586
2018-10-20 05:45:27qagrensetkeywords: + patch
stage: patch review
pull_requests: + pull_request9340
2018-10-20 05:36:26xtreaksetnosy: + xtreak
2018-10-20 01:30:13pablogsalsetnosy: + pablogsal
2018-10-19 05:29:50serhiy.storchakasetnosy: + brett.cannon, ncoghlan, eric.snow
2018-10-19 04:00:41qagrencreate