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

2018-10-18 Thread Quentin Agren


New submission from Quentin Agren :

Hi,

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

Description of the issue:
imporlib logs 'wrote ' 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 
<https://bugs.python.org/issue35024>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2018-10-19 Thread Quentin Agren


Change by Quentin Agren :


--
keywords: +patch
pull_requests: +9340
stage:  -> patch review

___
Python tracker 
<https://bugs.python.org/issue35024>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35073] 'from app import __init__' behaves differently with native import and importlib

2018-10-25 Thread Quentin Agren


New submission from Quentin Agren :

I'm running Python 3.6 on Ubuntu 16.04

I don't know if this should qualify as a bug, but I noticed the following 
behavior difference in the (contrived?) scenario of directly importing 
'__init__' from a package:

## Setup ##

mkdir app
echo 'print(f"Executing app/__init__.py as {__name__}")' > app/__init__.py

## Native: executes __init__ *once* ##

python -c 'from app import __init__'
# Output:
# Executing app/__init__.py as app

## Importlib: executes __init__ *twice* ##

python -c "import importlib; importlib.import_module('.__init__', 'app')"
# Output:
# Executing app/__init__.py as app
# Executing app/__init__.py as app.__init__

Note in addition that absolute import (either with importlib or native) 
executes '__init__' twice.

--
components: Library (Lib)
messages: 328512
nosy: qagren
priority: normal
severity: normal
status: open
title: 'from app import __init__' behaves differently with native import and 
importlib
type: behavior
versions: Python 3.6

___
Python tracker 
<https://bugs.python.org/issue35073>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35073] 'from app import __init__' behaves differently with native import and importlib

2018-10-26 Thread Quentin Agren


Quentin Agren  added the comment:

Sorry for the misunderstanding, and thanks for clarifying!

So essentially what I am getting by `from app import __init__` is the 
`__init__` method of the module object bound to the name `app`.

However if I have a submodule `app/myapp.py`, `from app import myapp` will 
import it and bind it to the name `myapp`, whereas 
`importlib.import_module('app').myapp` raises AttributeError, so I guess the 
two forms not totally equivalent...


Anyways, I'll investigate deeper before creating an issue henceforth :)

--
stage:  -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue35073>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com