This repository was archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
PythonImportGuidelines
kkress edited this page Sep 12, 2012
·
8 revisions
In general PEP-8 import ordering should be used. However there are a few additions.
- Imports should be grouped in the following order:
- standard library imports
- related third party imports
- Reddit packages not part of the local package scope
- Reddit packages part of the the local package scope or sub scopes of the current package.
- No relative imports: All imports should have fully qualified package names.
- for each imported group the order of imports should be:
-
import <package>.<module>style lines in alphabetical order -
from <package>.<module> import <symbol>style in alphabetical order
-
- Only one
fromline per module is permitted - If there are too many symbols for a single line of < 80 characters then the import should be indented.
It should look as follows:
from foo import (#Classes
Foo,
Bar,
Baz,
#Functions
lookup_foo,
lookup_all,
#Constants/Variables
ALL_USERS,
OTHER_THING,
)
- This should only be used if there are 10 or fewer symbols to import. Otherwise consider using an
import <module> as <alias>and prefixing all symbols from that module with the appropriate alias.
- Each file should have an
__all__declaration
It should look like:
__all__ = [
#Constants Only, use @export for functions/classes
]
- Any functions or classes the need to be exported should use the @export decorator found in r2.lib.export