Brett Cannon wrote: > I just discovered frozen packages set their __path__ simply to their > name and not to a list as expected (http://bugs.python.org/issue4211). > This made me think about the 'path' argument to find_module() and > whether it can be treated as simply a hint or should always be > seriously looked at. > > Take frozen modules, for instance. If the 'path' argument is meant to > always be considered then if a frozen module is within a package a > check should be done to make sure that the parent package is in 'path' > somewhere. But if it is simply a hint, then 'path' should be ignored > and whether the module can be found should depend fully on > imp.is_frozen(). > > So, what do people think? Should 'path' for find_module() always be > taken into consideration, or only when it happens to be convenient?
>From PEP 302: importer.find_module(fullname, path=None) This method will be called with the fully qualified name of the module. If the importer is installed on sys.meta_path, it will receive a second argument, which is None for a top-level module, or package.__path__ for submodules or subpackages[7]. It should return a loader object if the module was found, or None if it wasn't. If find_module() raises an exception, it will be propagated to the caller, aborting the import. [7] The path argument to importer.find_module() is there because the pkg.__path__ variable may be needed at this point. It may either come from the actual parent module or be supplied by imp.find_module() or the proposed imp.get_loader() function. Note the first "may" in the footnote. If an importer doesn't need pkg.__path__ to find submodules then it isn't obliged to use it, but the import machinery provides it as a convenience. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | 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