[issue16489] importlib find_loader returns a loader for a non existent module

2012-11-17 Thread Xavier de Gaye

Xavier de Gaye added the comment:

I was bitten by this behavior while, new to the importlib library, I
was trying to understand if one has to call recursively find_loader
for a dotted module name (in the way it must be done when using
imp.find_module), since the documentation on find_loader is not
clear. My test environment happened to be at that time:

foo.py
mypackage
__init__.py
foo.py

and at first I could not understand why find_loader('mypackage.foo')
was returning a loader, while find_loader('logging.handlers') was
returning None.

It is fine with me to consider that this behavior does not have
to be changed and to close this discussion.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16489
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16489] importlib find_loader returns a loader for a non existent module

2012-11-17 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 358be7742377 by Brett Cannon in branch '3.3':
Issue #16489: Make it clearer that importlib.find_loader() requires
http://hg.python.org/cpython/rev/358be7742377

New changeset ba1d7447bd1b by Brett Cannon in branch 'default':
Merge fix for #16489 from 3.3
http://hg.python.org/cpython/rev/ba1d7447bd1b

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16489
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16489] importlib find_loader returns a loader for a non existent module

2012-11-17 Thread Brett Cannon

Brett Cannon added the comment:

I clarified the wording in 3.3 and default. I also opened issue #16492 to add a 
keyword-only argument to find_loader() to have it import parent packages for 
you if you so desire.

--
resolution: invalid - fixed
stage:  - committed/rejected

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16489
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16489] importlib find_loader returns a loader for a non existent module

2012-11-17 Thread Xavier de Gaye

Xavier de Gaye added the comment:

Thanks, this is great!

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16489
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16489] importlib find_loader returns a loader for a non existent module

2012-11-16 Thread Xavier de Gaye

New submission from Xavier de Gaye:

Create the following tree:

foo.py
mypackage
__init__.py

and get a loader for the non existent module 'mypackage.foo'.

$ mkdir tmp
$ cd tmp
$ foo.py
$ mkdir mypackage
$ mypackage/__init__.py
$ ./python
Python 3.4.0a0 (default:53a7c2226a2b, Nov  9 2012, 16:47:41) 
[GCC 4.3.2] on linux
Type help, copyright, credits or license for more information.
 import importlib
 importlib.find_loader('mypackage').get_filename()
'./mypackage/__init__.py'
 importlib.find_loader('mypackage.foo').get_filename()
'./foo.py'



find_loader should return None in this case.

--
components: Library (Lib)
messages: 175697
nosy: xdegaye
priority: normal
severity: normal
status: open
title: importlib find_loader returns a loader for a non existent module
type: behavior
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16489
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16489] importlib find_loader returns a loader for a non existent module

2012-11-16 Thread Xavier de Gaye

Xavier de Gaye added the comment:

And yes, find_loader returns None, when correctly invoked with the
path argument:

 importlib.find_loader('mypackage.foo', ['./mypackage/'])


--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16489
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16489] importlib find_loader returns a loader for a non existent module

2012-11-16 Thread R. David Murray

R. David Murray added the comment:

Not necessarily.  The fact that there is nothing to load doesn't mean it isn't 
the right loader if there *was* something to load.  But I'll leave it to the 
import experts to say what the expected behavior is.  I'll admit that I can't 
figure it out from a quick perusal of the docs and PEP, so I'd say that 
regardless of what the correct behavior is there is at least a doc bug here.

--
nosy: +brett.cannon, eric.smith, r.david.murray

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16489
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16489] importlib find_loader returns a loader for a non existent module

2012-11-16 Thread Brett Cannon

Brett Cannon added the comment:

Everything is working as expected; you left out the path argument::

  importlib.find_loader('package.foo', ['package'])

This works the way it does because otherwise we would have to stat every single 
time from the top level on down and that is extremely costly.

--
resolution:  - invalid
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16489
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16489] importlib find_loader returns a loader for a non existent module

2012-11-16 Thread Xavier de Gaye

Xavier de Gaye added the comment:

Maybe find_loader could check its parameters, notice that the name is a
dotted name, that path is None and in this case, not return a loader ?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16489
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16489] importlib find_loader returns a loader for a non existent module

2012-11-16 Thread Brett Cannon

Brett Cannon added the comment:

That won't work as frozen and builtin modules don't care about the path.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16489
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16489] importlib find_loader returns a loader for a non existent module

2012-11-16 Thread Xavier de Gaye

Xavier de Gaye added the comment:

 Not necessarily.  The fact that there is nothing to load doesn't
 mean it isn't the right loader if there *was* something to load.

But it is not even the right loader if there *was* something to load,
as get_filename() returns './foo.py' which is wrong even if
mypackage/foo.py had existed.  It should have returned
'./mypackage/foo.py' to be an acceptable loader for a would-be
mypackage.foo module.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16489
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16489] importlib find_loader returns a loader for a non existent module

2012-11-16 Thread Xavier de Gaye

Xavier de Gaye added the comment:

If one would want to fix this, one way to do it could be to change the
following two methods of the PathFinder class such that:

find_module() does not set path to sys.path when its path argument
is None, so as to keep this information for _get_loader() to
process it later

_get_loader() sets path to sys.path when its path argument is None
and returns a None loader when a loader has been found by a finder
and:
- this finder is a FileFinder instance
- the _get_loader() path argument is None
- the module name is a dotted name

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16489
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16489] importlib find_loader returns a loader for a non existent module

2012-11-16 Thread Brett Cannon

Brett Cannon added the comment:

Feel free to submit a patch, but I'm personally not motivated enough to try to 
change this on my own.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16489
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16489] importlib find_loader returns a loader for a non existent module

2012-11-16 Thread Eric V. Smith

Eric V. Smith added the comment:

It might be more motivating if you (Xavier de Gaye) could let us know of a 
real-world problem caused by this behavior.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16489
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com