Author qagren
Recipients qagren
Date 2018-10-19.04:00:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1539921641.62.0.788709270274.issue35024@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-10-19 04:00:41qagrensetrecipients: + qagren
2018-10-19 04:00:41qagrensetmessageid: <1539921641.62.0.788709270274.issue35024@psf.upfronthosting.co.za>
2018-10-19 04:00:41qagrenlinkissue35024 messages
2018-10-19 04:00:41qagrencreate