Skip to content

Commit 5ea1f49

Browse files
[primer] Clarify location diff wording and robustify key iteration
- format_span now returns `line:col`-`endLine:endCol` spans, and message_diff says "Moved from {old} to {new}" — avoids ambiguity between span-range and movement. - message_diff iterates set(old) | set(new) so keys present only in new are also detected.
1 parent 1bfac75 commit 5ea1f49

5 files changed

Lines changed: 9 additions & 9 deletions

File tree

pylint/testutils/_primer/comparator.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def format_span(msg: JSONMessage) -> str:
6868
end_line = msg.get("endLine")
6969
end_col = msg.get("endColumn")
7070
if end_line is not None and end_col is not None:
71-
return f"from `{start}` to `{end_line}:{end_col}`"
72-
return f"at `{start}`"
71+
return f"`{start}`-`{end_line}:{end_col}`"
72+
return f"`{start}`"
7373

7474

7575
def message_diff(old: JSONMessage, new: JSONMessage) -> str:
@@ -80,14 +80,14 @@ def message_diff(old: JSONMessage, new: JSONMessage) -> str:
8080
renders them with red/green highlighting.
8181
"""
8282
changed_keys: set[str] = set()
83-
for key in old:
84-
if old[key] != new[key]: # type: ignore[literal-required]
83+
for key in set(old) | set(new):
84+
if old.get(key) != new.get(key):
8585
changed_keys.add(key)
8686

8787
parts: list[str] = []
8888
# Location: combine line/column/endLine/endColumn into one sentence.
8989
if changed_keys & _LOCATION_KEYS:
90-
parts.append(f"Was raised {format_span(old)}, now {format_span(new)}.")
90+
parts.append(f"Moved from {format_span(old)} to {format_span(new)}.")
9191

9292
# Other fields (typically ``message`` or ``type``).
9393
for key in sorted(changed_keys - _LOCATION_KEYS):

tests/testutils/_primer/cases/line_moved/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Changed messages:
88
<details>
99

1010
1) [too-complex](https://github.com/pylint-dev/astroid/blob/123456789abcdef/astroid/node_classes.py#L103):
11-
Was raised from `100:0` to `100:15`, now from `103:0` to `103:15`.
11+
Moved from `100:0`-`100:15` to `103:0`-`103:15`.
1212
</details>
1313

1414
*This comment was generated for commit v2.14.2*

tests/testutils/_primer/cases/message_changed_line/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Changed messages:
88
<details>
99

1010
1) [too-complex](https://github.com/pylint-dev/astroid/blob/123456789abcdef/astroid/node_classes.py#L103):
11-
Was raised from `100:0` to `100:15`, now from `103:0` to `103:15`.
11+
Moved from `100:0`-`100:15` to `103:0`-`103:15`.
1212

1313
```diff
1414
- 'my_function' is too complex. The McCabe rating is 18

tests/testutils/_primer/cases/mixed_changes/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Changed messages:
1414
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
```
1616
2) [too-complex](https://github.com/pylint-dev/astroid/blob/123456789abcdef/astroid/node_classes.py#L105):
17-
Was raised from `100:0` to `100:15`, now from `105:0` to `105:15`.
17+
Moved from `100:0`-`100:15` to `105:0`-`105:15`.
1818

1919
confidence: `UNDEFINED` → `HIGH`
2020

tests/testutils/_primer/cases/multi_package/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Changed messages:
88
<details>
99

1010
1) [too-complex](https://github.com/pylint-dev/astroid/blob/123456789abcdef/astroid/node_classes.py#L105):
11-
Was raised from `100:0` to `100:15`, now from `105:0` to `105:15`.
11+
Moved from `100:0`-`100:15` to `105:0`-`105:15`.
1212

1313
```diff
1414
- 'my_function' is too complex. The McCabe rating is 18

0 commit comments

Comments
 (0)