equal
deleted
inserted
replaced
409 * Symbols can only be imported from specific modules (see |
409 * Symbols can only be imported from specific modules (see |
410 `allowsymbolimports`). For other modules, first import the module then |
410 `allowsymbolimports`). For other modules, first import the module then |
411 assign the symbol to a module-level variable. In addition, these imports |
411 assign the symbol to a module-level variable. In addition, these imports |
412 must be performed before other local imports. This rule only |
412 must be performed before other local imports. This rule only |
413 applies to import statements outside of any blocks. |
413 applies to import statements outside of any blocks. |
414 * Relative imports from the standard library are not allowed. |
414 * Relative imports from the standard library are not allowed, unless that |
|
415 library is also a local module. |
415 * Certain modules must be aliased to alternate names to avoid aliasing |
416 * Certain modules must be aliased to alternate names to avoid aliasing |
416 and readability problems. See `requirealias`. |
417 and readability problems. See `requirealias`. |
417 """ |
418 """ |
418 if not isinstance(module, str): |
419 if not isinstance(module, str): |
419 module = module.decode('ascii') |
420 module = module.decode('ascii') |
491 yield msg('import should be relative: %s', fullname) |
492 yield msg('import should be relative: %s', fullname) |
492 |
493 |
493 # __future__ is special since it needs to come first and use |
494 # __future__ is special since it needs to come first and use |
494 # symbol import. |
495 # symbol import. |
495 if fullname != '__future__': |
496 if fullname != '__future__': |
496 if not fullname or fullname in stdlib_modules: |
497 if not fullname or ( |
|
498 fullname in stdlib_modules |
|
499 and fullname not in localmods |
|
500 and fullname + '.__init__' not in localmods): |
497 yield msg('relative import of stdlib module') |
501 yield msg('relative import of stdlib module') |
498 else: |
502 else: |
499 seenlocal = fullname |
503 seenlocal = fullname |
500 |
504 |
501 # Direct symbol import is only allowed from certain modules and |
505 # Direct symbol import is only allowed from certain modules and |