You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
reveal_type / reveal_locals should not use "error" but "note" #6901
For integration of mypy's output (and in general) it would be better to have them treated as notes, not errors.
app.py:336: note: Revealed type is 'Any'
app.py:338: note: Revealed local types are:
app.py:338: note: content: Any
app.py:338: note: data: Any
While at it, it would be nice to have e.g. a " - " prefix (i.e. list) with the continuation lines after "Revealed local types are:" (also related: #6526).
diff --git i/mypy/messages.py w/mypy/messages.py
index 92b0b6ce..45d66afb 100644
--- i/mypy/messages.py+++ w/mypy/messages.py@@ -1068,15 +1068,15 @@ def invalid_signature_for_special_method(
self.fail('Invalid signature "{}" for "{}"'.format(func_type, method_name), context)
def reveal_type(self, typ: Type, context: Context) -> None:
- self.fail('Revealed type is \'{}\''.format(typ), context)+ self.note('Revealed type is \'{}\''.format(typ), context)
def reveal_locals(self, type_map: Dict[str, Optional[Type]], context: Context) -> None:
# To ensure that the output is predictable on Python < 3.6,
# use an ordered dictionary sorted by variable name
sorted_locals = OrderedDict(sorted(type_map.items(), key=lambda t: t[0]))
- self.fail("Revealed local types are:", context)+ self.note("Revealed local types are:", context)
for line in ['{}: {}'.format(k, v) for k, v in sorted_locals.items()]:
- self.fail(line, context)+ self.note(line, context)
def unsupported_type_type(self, item: Type, context: Context) -> None:
self.fail('Unsupported type Type[{}]'.format(self.format(item)), context)
Hey all, I also think note is more appropriate than errors to denote output from reveal_locals and reveal_type, but we should be aware that this was a breaking change.
I wrote a tool (that I'm about to publish on Sublime Text's Package Control) that automatically inserts reveal_locals and reveal_type functions into the buffer, runs mypy on the resulting text, parses the output and displays the results. It suddenly broke when I updated mypy, because it was looking for "errors" instead of "notes" in the output.
Activity
ilevkivskyi commentedon May 26, 2019
In principle I like this idea, but how will you update hundreds of existing test cases?
blueyed commentedon Jun 1, 2019
I assume the tests could be updated once, e.g using
sed.Will give it a try.
What about indenting following lines with
reveal_locals?Use level "note" for reveal_type and reveal_locals
ilevkivskyi commentedon Jun 1, 2019
I think this would make sense.
Use level "note" for reveal_type and reveal_locals
Use level "note" for reveal_type and reveal_locals
Use level "note" for reveal_type and reveal_locals
Use level "note" for reveal_type and reveal_locals (#6919)
Use level "note" for reveal_type and reveal_locals (#6919)
Use level "note" for reveal_type and reveal_locals (python#6919)
kylebebak commentedon Jun 30, 2019
Hey all, I also think
noteis more appropriate thanerrorsto denote output fromreveal_localsandreveal_type, but we should be aware that this was a breaking change.I wrote a tool (that I'm about to publish on Sublime Text's Package Control) that automatically inserts
reveal_localsandreveal_typefunctions into the buffer, runs mypy on the resulting text, parses the output and displays the results. It suddenly broke when I updated mypy, because it was looking for "errors" instead of "notes" in the output.Hopefully there's no need to change this again!
gvanrossum commentedon Jun 30, 2019
Yeah, unfortunately we can't guarantee that error messages will be backwards compatible.