[issue35024] Incorrect logging in importlib when '.pyc' file creation fails

Quentin Agren report at bugs.python.org
Fri Oct 19 00:00:41 EDT 2018


New submission from Quentin Agren <quentin.agren at gmail.com>:

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.

----------
components: Library (Lib)
messages: 328029
nosy: qagren
priority: normal
severity: normal
status: open
title: Incorrect logging in importlib when '.pyc' file creation fails
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35024>
_______________________________________


More information about the Python-bugs-list mailing list