-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
component: build systemBazel, CMake, dependencies, memory checkers, lintersBazel, CMake, dependencies, memory checkers, lintersconfiguration: pythonpriority: mediumtype: feature request
Description
Should formalize import statements
Relates #13572 (issue) in that this should be a idempotent projection to one format (ideal thing for linting)
Steps:
- Styleguide PR
- Lint implementation + unittests
- Application to codebase
Some design thoughts:
- From PEP008, should delineate builtin, third, and first-part sources
- Should be extensible for Anzu
- Should handle ensuring
pydrake
is imported beforetorch
(for Anzu) - Should also handle
mut
andmut_*
modules being imported first (or encourage it, as well)
My preferred styles and ordering (aside from the PEP8 sections):
# Basic import
import module
# Single symbol import
from module import SingleSymbol
# Module import from package
from package_1.sub_package import module
# import package_1.sub_package.module as module # Nah. I think this is silly, trying too hard for line-lexical sorting.
# Abbreviated alias
import package_2.sub_package.module as m2
# Super line wrap
from package_3.sub_package.sub_sub_package.sub_sub_sub_package import ( # noqa
LineLengthExceeded,
)
# Symbol imports
# - No linewrap needed
from yyy_module import YyySymbol1, YyySymbol2
# - Linewrap needed
from zzz_module import (
ZzzSymbolA,
ZzzSymbolB,
ZzzSymbolC,
ZzzSymbolD,
)
EDIT: On second thought, perhaps import pkg.sub as sub
is better than from pkg import sub
, just as a way to show that it's a module, not a symbol.
Metadata
Metadata
Assignees
Labels
component: build systemBazel, CMake, dependencies, memory checkers, lintersBazel, CMake, dependencies, memory checkers, lintersconfiguration: pythonpriority: mediumtype: feature request
Type
Projects
Status
On deck