[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-06-15 Thread Brett Cannon
Changes by Brett Cannon : -- resolution: -> fixed stage: patch review -> committed/rejected status: open -> closed ___ Python tracker ___ ___

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-06-15 Thread Roundup Robot
Roundup Robot added the comment: New changeset 240b7467e65c by Brett Cannon in branch 'default': Issue #14938: importlib.abc.SourceLoader.is_package() now takes the http://hg.python.org/cpython/rev/240b7467e65c -- nosy: +python-dev ___ Python tracker

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-06-03 Thread Ronan Lamy
Ronan Lamy added the comment: I'm not sure that it's enough to test is_package() because that only involves the loader and not the interaction between it and FileFinder. That's the reason why my test works at a higher level. BTW, I sent the contributor agreement. --

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-06-02 Thread Brett Cannon
Brett Cannon added the comment: Thanks for the patch, Ronan! The fix seems fine and I will have a more thorough look at the test later and figure out where it should go (probably only going to worry about testing is_package() directly since that was the semantic disconnect). I will also updat

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-06-01 Thread Ronan Lamy
Ronan Lamy added the comment: OK, that makes sense pragmatically. Here's the patch then. I wasn't sure where to put the test, it doesn't actually have much in common with the rest of Lib/importlib/test/import_/test_packages.py but the name fits, so... -- Added file: http://bugs.pytho

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-06-01 Thread Brett Cannon
Brett Cannon added the comment: I have yet to see anyone use a URL loader in serious code beyond people just using it as an example. What I do see is lots of custom zipfile importers and thus for the majority if people this will continue to make sense. And even with a URL loader, get_filename

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-06-01 Thread Ronan Lamy
Ronan Lamy added the comment: Your second solution is simple and solves the problem, so I guess that's it, then. Still, I don't really understand the purpose of SourceLoader, which makes me uneasy about the implementation of _LoaderBasics.is_package(). It seems to be meant to load an arbitr

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-06-01 Thread Brett Cannon
Brett Cannon added the comment: I think you misunderstood what I was suggesting as a solution: there is no conversion of module name to file name. It would simply be:: fullname.rpartition('.')[2] == os.path.splitext(os.path.split(self.path)[1])[0] for path comparison. But honestly since __ini

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-06-01 Thread Ronan Lamy
Ronan Lamy added the comment: Here's a preliminary patch, without tests or documentation, implementing my approach (adding an optional is_package=False to FileLoader.__init__()). Next question (quite independent of the chosen implementation): how should this be tested? -- keywords: +

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-05-31 Thread Ronan Lamy
Ronan Lamy added the comment: That would force the Loaders to know how to convert a module name into a file path, which isn't the case now since FileLoader.get_filename() is just a shim that returns self.path. So I'd rather add an optional argument to FileLoader. Actually, I feel that the cle

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-05-31 Thread Brett Cannon
Brett Cannon added the comment: I see what you mean about the discrepancy, but you don't need to complicate the constructor to get the desired result. If you have is_package() check if the module name ends in __init__ to skip the package check and just say False (e.g. only if the path ends in

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-05-30 Thread Ronan Lamy
Ronan Lamy added the comment: Reverting to the previous behaviour, then? OK. As I understand it, the issue comes from a DRY violation: both FileFinder.find_loader() and _LoaderBasics.is_package() have their own notion of what is a package and they disagree. Since the finder needs to know what

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-05-30 Thread Brett Cannon
Brett Cannon added the comment: If you directly import __init__ then it would just be a module within the package (the "magic" of packages should stay with the implicit interpretation of __init__). -- ___ Python tracker

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-05-29 Thread Ronan Lamy
Ronan Lamy added the comment: Well, I can try. I have trouble wrapping my head around all the finders and loaders, but I'm slowly understanding what does what. What I don't know is what the expected behaviour is. Should my_pkg.__init__ be allowed to exist as a separate module (that's backward

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-05-29 Thread Brett Cannon
Brett Cannon added the comment: If you can come up with a patch to fix this in a way that is not messy then I will be happy to look at it. -- ___ Python tracker ___ ___

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-05-28 Thread Ronan Lamy
Ronan Lamy added the comment: Grmf. I didn't mean to change the status. -- resolution: -> wont fix status: open -> closed ___ Python tracker ___ ___

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-05-28 Thread Ronan Lamy
Ronan Lamy added the comment: my_pkg.__init__ isn't treated as just another module but as a package. That is the reason why the bogus my_pkg.__init__.module1 is created, I guess: >>> import sys >>> sorted(name for name in sys.modules if name.startswith('my_')) [] >>> import my_pkg.__init__ >>>

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-05-28 Thread Arfrever Frehtes Taifersar Arahesis
Changes by Arfrever Frehtes Taifersar Arahesis : -- nosy: +Arfrever ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscri

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-05-28 Thread Brett Cannon
Brett Cannon added the comment: You can't have it both ways. If you explicitly import __init__ then it becomes just another module to Python, but you still need the implicit package module (i.e. without the __init__ name) for everything else to work since so much of the import system relies o

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-05-28 Thread Aaron Meurer
Changes by Aaron Meurer : -- nosy: +Aaron.Meurer ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.py

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-05-28 Thread R. David Murray
Changes by R. David Murray : -- nosy: +brett.cannon ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail

[issue14938] 'import my_pkg.__init__' creates duplicate modules

2012-05-28 Thread Ronan Lamy
New submission from Ronan Lamy : If an __init__.py file contains relative imports, doing 'import my_pkg.__init__' or calling __import__('my_pkg.__init__') creates duplicate versions of the relatively imported modules, which (I believe) causes cryptic errors in some cases (cf. the metaclass iss