Specify that load_module is to raise ImportError if an error has occurred and

no exceptino is being propagated or it has been asked to load a module that it
cannot.

Also specify that __name__ must be set on all loaded modules.
This commit is contained in:
Brett Cannon 2007-04-29 20:19:50 +00:00
parent fd3f447b80
commit e2d0295f0f
1 changed files with 10 additions and 3 deletions

View File

@ -223,9 +223,13 @@ Specification part 1: The Importer Protocol
loader.load_module(fullname) loader.load_module(fullname)
This method returns the loaded module. In many cases the importer This method returns the loaded module or raises and exception,
and loader can be one and the same object: importer.find_module() preferably ImportError if an existing exception is not being
would just return self. propagated. If load_module() is asked to laod a module that it
cannot, ImportError is to be raised.
In many cases the importer and loader can be one and the same
object: importer.find_module() would just return self.
The 'fullname' argument of both methods is the fully qualified The 'fullname' argument of both methods is the fully qualified
module name, for example "spam.eggs.ham". As explained above, when module name, for example "spam.eggs.ham". As explained above, when
@ -267,6 +271,9 @@ Specification part 1: The Importer Protocol
not having a __file__ attribute at all is reserved for built-in not having a __file__ attribute at all is reserved for built-in
modules. modules.
- The __name__ attribute must be set. If one uses
imp.new_module() then the attribute is set automatically.
- If it's a package, the __path__ variable must be set. This must - If it's a package, the __path__ variable must be set. This must
be a list, but may be empty if __path__ has no further be a list, but may be empty if __path__ has no further
significance to the importer (more on this later). significance to the importer (more on this later).