Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue14660] Implement PEP 420: Implicit Namespace Packages

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Apr 24, 2012, 4:08 AM

Post #1 of 13 (183 views)
Permalink
[issue14660] Implement PEP 420: Implicit Namespace Packages

New submission from Eric V. Smith <eric [at] trueblade>:

I have created a branch features/pep-420 where I'll be developing a proof of concept implementation of PEP 420.

I've checked in a basic version, but it has these issues:

- We need to decide how finders communicate that they've found part of
a namespace package. Per Brett's suggestion, I'm currently returning a
string that means "the returned path is part of a namespace package".
I think that's an okay design.

- I guess we need to create a "namespace loader", so we can initialize __loader__. It's a little odd because it would be a loader for which there's no need for a find_module method. I'm currently setting __loader__ to the finder, which is completely wrong, but keeps things working.

- test_import and test_importlib both fail because they're checking
that imports with no __init__.py fail. Those tests need to be removed.

- There are no tests yet.

----------
assignee: eric.smith
messages: 159131
nosy: barry, brett.cannon, eric.smith, jason.coombs
priority: normal
severity: normal
status: open
title: Implement PEP 420: Implicit Namespace Packages
type: enhancement
versions: Python 3.3

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14660>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Apr 24, 2012, 7:42 AM

Post #2 of 13 (177 views)
Permalink
[issue14660] Implement PEP 420: Implicit Namespace Packages [In reply to]

Brett Cannon <brett [at] python> added the comment:

Loaders are not meant to have a find_module method; that is purely for finders which can be distinct objects. So having a namespace loader is expected and there is no expectation that it have a find_module method (actually almost all of the loaders in importlib lack a find_module method).

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14660>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Apr 24, 2012, 8:00 AM

Post #3 of 13 (173 views)
Permalink
[issue14660] Implement PEP 420: Implicit Namespace Packages [In reply to]

Eric V. Smith <eric [at] trueblade> added the comment:

Right, that's a typo. I meant load_module(). I'm currently working on implementing the loader for namespace modules, so my comment about the loader is premature.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14660>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Apr 24, 2012, 8:37 AM

Post #4 of 13 (171 views)
Permalink
[issue14660] Implement PEP 420: Implicit Namespace Packages [In reply to]

Eric V. Smith <eric [at] trueblade> added the comment:

I created the NamespaceLoader in the feature branch. It has a load_module, but it's only ever called by the code in PathFinder.load_module:

loader = NamespaceLoader(namespace_path)
return loader.load_module(fullname)

namespace_path is what will become module.__path__. In order to keep the load_module API (single fullname argument), I pass it in to the constructor. There's no particular need for it to follow that API, but it does.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14660>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Apr 24, 2012, 8:57 AM

Post #5 of 13 (170 views)
Permalink
[issue14660] Implement PEP 420: Implicit Namespace Packages [In reply to]

Brett Cannon <brett [at] python> added the comment:

Yeah, having to pass in the name to load_module is silly. I'm seriously considering making it optional for some loaders when the name was passed in to the constructor.

One thing I would like to see is that PathFinder take a new, keyword-only argument of 'namespace_loader' or something that takes an object which is called with the module name and the list of paths to use for __path__ (and thus __path__[0] becomes __file__). That way it can be controlled by users if desired. I'm also fine with it having a default value of NamespaceLoader to start since I don't see people needing to comprehend what they are allowing in this case as I do for general file loaders.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14660>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Apr 24, 2012, 2:54 PM

Post #6 of 13 (168 views)
Permalink
[issue14660] Implement PEP 420: Implicit Namespace Packages [In reply to]

Changes by Eric Snow <ericsnowcurrently [at] gmail>:


----------
nosy: +eric.snow

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14660>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Apr 25, 2012, 5:47 AM

Post #7 of 13 (169 views)
Permalink
[issue14660] Implement PEP 420: Implicit Namespace Packages [In reply to]

Eric V. Smith <eric [at] trueblade> added the comment:

I'd really prefer something like:

return load_ns_module(fullname, namespace_path)

The point being that load_module() as defined in PEP 302 will never be called on NamespaceLoader. The loader only needs to exist to set module.__loader__, and load_module() would never be called from there.

So we could pass in a callable named load_ns_module to PathFinder.

Then NamespaceLoader's load_module function could be named load_ns_module, made a class or static method.

I think I'll experiment with this.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14660>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Apr 25, 2012, 5:50 AM

Post #8 of 13 (176 views)
Permalink
[issue14660] Implement PEP 420: Implicit Namespace Packages [In reply to]

Changes by Yury Selivanov <yselivanov [at] gmail>:


----------
nosy: +Yury.Selivanov

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14660>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Apr 25, 2012, 7:51 AM

Post #9 of 13 (173 views)
Permalink
[issue14660] Implement PEP 420: Implicit Namespace Packages [In reply to]

Brett Cannon <brett [at] python> added the comment:

What do you mean the loader is only needed to set __loader__? You need the loader to create the module (or find it in sys.modules to reload), and set all the attributes properly. If you do this then reloading namespace modules will become a special case compared to other loaders as imp.reload() calls module.__loader__.load_module().

This also prevents the creation of an importlib.find_module() which would return the loader to replace imp.find_module() since you now split the API.

I realize the finder/loader dichotomy seems superfluous (and most of the time it is), but it has already been heavily exposed and relied on and deviating from it for namespace modules runs the risk of hurting introspection.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14660>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Apr 25, 2012, 7:56 AM

Post #10 of 13 (169 views)
Permalink
[issue14660] Implement PEP 420: Implicit Namespace Packages [In reply to]

Eric V. Smith <eric [at] trueblade> added the comment:

Ah. I didn't realize that reload called load_module. I'll back out the change I just made, then.

My point was that the original call to load_module isn't made through the normal "a finder returned me a loader, so I'll call it" code path. It's always made through the "I know I have a NamespaceLoader" path.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14660>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Apr 25, 2012, 8:00 AM

Post #11 of 13 (168 views)
Permalink
[issue14660] Implement PEP 420: Implicit Namespace Packages [In reply to]

Brett Cannon <brett [at] python> added the comment:

The joys of trying to shoehorn into an existing API. I mean short of adding a new sys.namespace_loader instead of an explicit keyword argument to FileFinder I can't think of a better solution.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14660>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Apr 25, 2012, 9:03 AM

Post #12 of 13 (169 views)
Permalink
[issue14660] Implement PEP 420: Implicit Namespace Packages [In reply to]

Changes by √Čric Araujo <merwok [at] netwok>:


----------
nosy: +eric.araujo

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14660>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Apr 30, 2012, 3:54 PM

Post #13 of 13 (171 views)
Permalink
[issue14660] Implement PEP 420: Implicit Namespace Packages [In reply to]

Eric V. Smith <eric [at] trueblade> added the comment:

I've modified zipimport to support namespace packages, and checked it in to the feature branch. This completes all of the functionality I think needs to be added. Next up is adding tests.

----------
stage: -> test needed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14660>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.