Skip to content

reveal_type / reveal_locals should not use "error" but "note" #6901

Closed

Description

@blueyed

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)

Activity

  1. ilevkivskyi commented on May 26, 2019

    @ilevkivskyi
    Member

    In principle I like this idea, but how will you update hundreds of existing test cases?

  2. blueyed commented on Jun 1, 2019

    @blueyed
    ContributorAuthor

    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?

  3. ilevkivskyi commented on Jun 1, 2019

    @ilevkivskyi
    Member

    What about indenting following lines with reveal_locals?

    I think this would make sense.

  4. added a commit that references this issue on Jun 18, 2019
    cb7b242
  5. added a commit that references this issue on Jun 18, 2019
    7cd264a
  6. added a commit that references this issue on Jun 23, 2019
    9f04044
  7. kylebebak commented on Jun 30, 2019

    @kylebebak

    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.

    Hopefully there's no need to change this again!

  8. gvanrossum commented on Jun 30, 2019

    @gvanrossum
    Member

    Yeah, unfortunately we can't guarantee that error messages will be backwards compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions