|
2 | 2 | from collections import namedtuple |
3 | 3 | from enum import IntEnum |
4 | 4 |
|
5 | | -from .__about__ import ( |
6 | | - __author__, __copyright__, __email__, __license__, __summary__, __title__, |
7 | | - __uri__, __version__, |
8 | | -) |
| 5 | +from .__about__ import __author__ |
| 6 | +from .__about__ import __copyright__ |
| 7 | +from .__about__ import __email__ |
| 8 | +from .__about__ import __license__ |
| 9 | +from .__about__ import __summary__ |
| 10 | +from .__about__ import __title__ |
| 11 | +from .__about__ import __uri__ |
| 12 | +from .__about__ import __version__ |
9 | 13 | from .stdlib_list import STDLIB_NAMES |
10 | 14 |
|
11 | 15 | __all__ = [ |
12 | | - "__title__", "__summary__", "__uri__", "__version__", "__author__", |
13 | | - "__email__", "__license__", "__copyright__", |
| 16 | + "__title__", |
| 17 | + "__summary__", |
| 18 | + "__uri__", |
| 19 | + "__version__", |
| 20 | + "__author__", |
| 21 | + "__email__", |
| 22 | + "__license__", |
| 23 | + "__copyright__", |
14 | 24 | ] |
15 | 25 |
|
16 | | -DEFAULT_IMPORT_ORDER_STYLE = 'cryptography' |
| 26 | +DEFAULT_IMPORT_ORDER_STYLE = "cryptography" |
17 | 27 |
|
18 | 28 | ClassifiedImport = namedtuple( |
19 | | - 'ClassifiedImport', |
20 | | - ['type', 'is_from', 'modules', 'names', 'lineno', 'level', 'package'], |
| 29 | + "ClassifiedImport", |
| 30 | + ["type", "is_from", "modules", "names", "lineno", "level", "package"], |
21 | 31 | ) |
22 | | -NewLine = namedtuple('NewLine', ['lineno']) |
| 32 | +NewLine = namedtuple("NewLine", ["lineno"]) |
23 | 33 |
|
24 | 34 |
|
25 | 35 | class ImportType(IntEnum): |
@@ -48,7 +58,7 @@ def get_package_names(name): |
48 | 58 | package_names = [last_package_name] |
49 | 59 |
|
50 | 60 | for part in reversed(parts): |
51 | | - last_package_name = f'{last_package_name}.{part}' |
| 61 | + last_package_name = f"{last_package_name}.{part}" |
52 | 62 | package_names.append(last_package_name) |
53 | 63 |
|
54 | 64 | return package_names |
@@ -79,22 +89,31 @@ def visit_Import(self, node): # noqa: N802 |
79 | 89 | else: |
80 | 90 | type_ = ImportType.MIXED |
81 | 91 | classified_import = ClassifiedImport( |
82 | | - type_, False, modules, [], node.lineno, 0, |
| 92 | + type_, |
| 93 | + False, |
| 94 | + modules, |
| 95 | + [], |
| 96 | + node.lineno, |
| 97 | + 0, |
83 | 98 | root_package_name(modules[0]), |
84 | 99 | ) |
85 | 100 | self.imports.append(classified_import) |
86 | 101 |
|
87 | 102 | def visit_ImportFrom(self, node): # noqa: N802 |
88 | 103 | if node.col_offset == 0: |
89 | | - module = node.module or '' |
| 104 | + module = node.module or "" |
90 | 105 | if node.level > 0: |
91 | 106 | type_ = ImportType.APPLICATION_RELATIVE |
92 | 107 | else: |
93 | 108 | type_ = self._classify_type(module) |
94 | 109 | names = [alias.name for alias in node.names] |
95 | 110 | classified_import = ClassifiedImport( |
96 | | - type_, True, [module], names, |
97 | | - node.lineno, node.level, |
| 111 | + type_, |
| 112 | + True, |
| 113 | + [module], |
| 114 | + names, |
| 115 | + node.lineno, |
| 116 | + node.level, |
98 | 117 | root_package_name(module), |
99 | 118 | ) |
100 | 119 | self.imports.append(classified_import) |
|
0 commit comments