|
Simple import statements take the following form: from module import name version; This declaration makes the named declaration within the specified module available. Module names are dot-separated sequences of names. All imports are absolute, not relative to the importing module's name. For example, the declaration from a.b.c import Example 1.0; finds a module named "a.b.c" and imports the item (pattern, for example) with the name "Example". Multiple named declarations can be accessed in one statement by separating them with commas: from a.b.c import Example 1.0, Another 2.3; Imported names must not clash with other names declared or imported in the same file. To avoid clashes, declarations can be renamed on import using an as clause: from one import Example 1.0; from two import Example 2.3 as ExampleTwo; When importing, it is not immediately an error to import a name that is not defined in the corresponding module, or to import from a non-existent module. It only becomes an error when the imported name is used in a context that requires it exists. In particular, when a pattern overrides another pattern (see the section on overrides), it is not an error if the overridden pattern does not exist. For all other uses of an imported name, it is an error if the import fails. Imported names are not available for further import. So, for example, if module B imports X from module A, module C cannot import X from B - it must import it directly from A. Version numbersAll top-level declarations are specified with a version number in major.minor format. When importing declarations, the version number must be specified. It is an error if the declaration imported is not compatible with the version specified in the import statement. The versions are compatible if the major number is identical and the minor number is at least as large as the requested version. So, for example, in from test import Example 2.3; the "Example" declaration from the "test" module is compatible if it has version 2.3 or 2.4, but not if it has version 2.2, 1.8 or 3.0. Circular importsCircular imports are not permitted. It is an error for file B to import from file A when file A is still being processed. |
