Skip to content

Commit e9775dd

Browse files
committed
Add comment guard to generated stubs
1 parent 2372c14 commit e9775dd

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

examples/example_pkg-stubs/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Generated with docstub. Manual edits will be overwritten!
2+
13
import _numpy as np_
24
from _basic import func_contains
35

examples/example_pkg-stubs/_basic.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Generated with docstub. Manual edits will be overwritten!
12
import configparser
23
import logging
34
from collections.abc import Sequence

examples/example_pkg-stubs/_numpy.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Generated with docstub. Manual edits will be overwritten!
12
import numpy as np
23
from numpy.typing import ArrayLike, NDArray
34

src/docstub/_stubs.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ class Py2StubTransformer(cst.CSTTransformer):
193193

194194
METADATA_DEPENDENCIES = (cst.metadata.PositionProvider,)
195195

196+
_docstub_generated_comment = cst.EmptyLine(
197+
comment=cst.Comment(
198+
"# Generated with docstub. Manual edits will be overwritten!"
199+
),
200+
)
201+
196202
# Equivalent to ` ...`, to replace the body of callables with
197203
_body_replacement = cst.SimpleStatementSuite(
198204
leading_whitespace=cst.SimpleWhitespace(value=" "),
@@ -462,7 +468,10 @@ def leave_Module(self, original_node, updated_node):
462468
import_nodes = self._parse_imports(
463469
required_imports, current_module=current_module
464470
)
465-
updated_node = updated_node.with_changes(body=import_nodes + updated_node.body)
471+
updated_node = updated_node.with_changes(
472+
header=[self._docstub_generated_comment],
473+
body=import_nodes + updated_node.body,
474+
)
466475
self._scope_stack.pop()
467476
self._pytypes_stack.pop()
468477
return updated_node

0 commit comments

Comments
 (0)