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