Skip to content

Commit 76ad17f

Browse files
committed
stubgen: Update order of imports in stub file
1 parent f1e36f2 commit 76ad17f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

generate-pdb-stubs/stubgen.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,19 @@ def _add_imports(root_node):
8585
])
8686
)
8787

88+
last_consecutive_import_node_index = 0
89+
encountered_first_import_node = False
90+
91+
for node in root_node.body:
92+
if isinstance(node, (ast.Import, ast.ImportFrom)):
93+
last_consecutive_import_node_index += 1
94+
encountered_first_import_node = True
95+
else:
96+
if encountered_first_import_node:
97+
break
98+
8899
for new_import_node in reversed(new_import_nodes.body):
89-
root_node.body.insert(0, new_import_node)
100+
root_node.body.insert(last_consecutive_import_node_index, new_import_node)
90101

91102

92103
def _remove_implementation_of_functions(root_node):

0 commit comments

Comments
 (0)