On Sat, Jul 31, 2010 at 3:57 PM, Daniel Waterworth <da.waterwo...@gmail.com> wrote: > @Nick: I suppose the simplest way to detect re-importation in the > general case, is to store a set of hashes of files that have been > imported. When a user tries to import a file where it's hash is > already in the set, a warning is generated. It's simpler than trying > to figure out all the different ways that a file can be imported, and > will also detect copied files. This is less infrastructure than you > were suggesting, but it's not a perfect solution.
Hashing every file on import would definitely be more overhead than just checking __file__ values (since we already calculate the latter, and regardless of how a file is imported, it needs to end up in sys.modules eventually). Besides, importing the same code under different names happens in several places in our own test suite (we use it to check that code behaviour doesn't change just because we import it differently), so we can hardly disable that behaviour. That said, I really don't think catching such a rare error is worth *any* runtime overhead. Just making "__main__" and the real module name refer to the same object in sys.modules is a different matter, but I'm not confident enough that I fully grasp the implications to do it without gathering feedback from a wider audience. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com