Skip to content

Commit 49825a9

Browse files
authored
Fix: Empty reveal locals ouput (#12400)
Fixes #12388 Co-authored-by: Cibin Mathew <[email protected]>
1 parent aabbf47 commit 49825a9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

mypy/messages.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,9 +1171,12 @@ def reveal_locals(self, type_map: Dict[str, Optional[Type]], context: Context) -
11711171
# To ensure that the output is predictable on Python < 3.6,
11721172
# use an ordered dictionary sorted by variable name
11731173
sorted_locals = OrderedDict(sorted(type_map.items(), key=lambda t: t[0]))
1174-
self.note("Revealed local types are:", context)
1175-
for line in [' {}: {}'.format(k, v) for k, v in sorted_locals.items()]:
1176-
self.note(line, context)
1174+
if sorted_locals:
1175+
self.note("Revealed local types are:", context)
1176+
for k, v in sorted_locals.items():
1177+
self.note(' {}: {}'.format(k, v), context)
1178+
else:
1179+
self.note("There are no locals to reveal", context)
11771180

11781181
def unsupported_type_type(self, item: Type, context: Context) -> None:
11791182
self.fail('Cannot instantiate type "Type[{}]"'.format(format_type_bare(item)), context)

0 commit comments

Comments
 (0)