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

Created on 2018-10-19 04:00 by qagren, last changed 2018-10-26 18:36 by miss-islington.

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

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' >
python -vv -c'import spam' 2>&1 | grep '__pycache__/spam'

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

SourceFileLoader.set_data() silences OSError raised by _write_atomic (importlib/ 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)
Date User Action Args
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