@@ -37,8 +37,21 @@ def normalize_body(text: str | None) -> str:
3737 return _WS .sub (" " , (text or "" ).strip ())
3838
3939
40+ def documented_source (node : Node ) -> str :
41+ """The component's code with its doc comment in front, when the code does not already hold it.
42+
43+ Languages like Rust keep doc comments (`///`) above the item, outside ``source_code``. Without
44+ them, a change that only documents behaviour would be invisible to the updater.
45+ """
46+ code = node .source_code or ""
47+ doc = (node .docstring or "" ).strip ()
48+ if doc and doc not in code :
49+ return f"{ doc } \n { code } "
50+ return code
51+
52+
4053def body_hash (node : Node ) -> str :
41- return hashlib .sha1 (normalize_body (node . source_code ).encode ("utf-8" )).hexdigest ()
54+ return hashlib .sha1 (normalize_body (documented_source ( node ) ).encode ("utf-8" )).hexdigest ()
4255
4356
4457def signature (node : Node ) -> dict [str , Any ]:
@@ -78,8 +91,8 @@ def truncate_to_tokens(text: str, max_tokens: int) -> str:
7891
7992
8093def unified_body_diff (old : Node | None , new : Node | None , label : str ) -> str :
81- old_lines = (old . source_code or "" ).splitlines (keepends = True ) if old else []
82- new_lines = (new . source_code or "" ).splitlines (keepends = True ) if new else []
94+ old_lines = documented_source (old ).splitlines (keepends = True ) if old else []
95+ new_lines = documented_source (new ).splitlines (keepends = True ) if new else []
8396 diff = difflib .unified_diff (
8497 old_lines , new_lines , fromfile = f"a/{ label } " , tofile = f"b/{ label } " , n = 2
8598 )
0 commit comments