Consistent quote wrapping around MessageBuilder.format#3873
Consistent quote wrapping around MessageBuilder.format#3873ilevkivskyi merged 29 commits intopython:masterfrom
Conversation
As all types are now quoted, this fixes places that they would be double-quoted in the protocol error messages.
test-data/unit/check-varargs.test
Outdated
| [out] | ||
| main:3: error: Argument 1 to "f" has incompatible type *List[A]; expected "B" | ||
| main:4: error: Argument 2 to "f" has incompatible type *List[A]; expected "B" | ||
| main:3: error: Argument 1 to "f" has incompatible type *"List[A]"; expected "B" |
There was a problem hiding this comment.
I think the star should be inside quotes for types like this.
|
Yep, agreed. Away from my laptop for the rest of the day, so I'll look at
it tomorrow.
…On Fri, 25 Aug 2017, 13:55 Ivan Levkivskyi ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In test-data/unit/check-varargs.test
<#3873 (comment)>:
> @@ -277,13 +277,13 @@ class A: pass
class B: pass
[builtins fixtures/list.pyi]
[out]
-main:3: error: Argument 1 to "f" has incompatible type *List[A]; expected "B"
-main:4: error: Argument 2 to "f" has incompatible type *List[A]; expected "B"
+main:3: error: Argument 1 to "f" has incompatible type *"List[A]"; expected "B"
I think the star should be inside quotes for types like this.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3873 (review)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAD1EGdO4LeDk4_FaIgrF--UUnLlC8Rlks5sbsQ1gaJpZM4PChFw>
.
|
|
So looking at how the formatting of the star-args is done, I think the formatting methods should probably be refactored a bit. Currently, the "public" API ( Also, as far as I can tell, the only way that |
…mple This makes the quoting code a little more consistent.
Instead update MessageBuilder.format to call _format_simple directly.
This is ._format_simple renamed to reflect its new intended contract.
This replaces strip_quotes(self.format(...)) calls, which have identical effect.
This adds a bare parameter to format_distinctly, so that MessageBuilder.incompatible_argument can take care of the quoting for its special case.
|
I've done that refactoring and addressed the comment from @ilevkivskyi. |
ilevkivskyi
left a comment
There was a problem hiding this comment.
Sorry for a delay, this looks almost ready, just few small comments.
| else: | ||
| # Default case; we simply have to return something meaningful here. | ||
| return 'object' | ||
| Convert a type to a relatively short string suitable for error messages. |
There was a problem hiding this comment.
Please add an empty line after the first docstring line.
There was a problem hiding this comment.
Line 189 is blank, it's just an existing blank line that the diff has kept from somewhere.
mypy/messages.py
Outdated
| .format_bare. | ||
| """ | ||
| ret = self.format_bare(typ, verbosity) | ||
| if ret in ['Module', 'overloaded function']: |
There was a problem hiding this comment.
I am not sure, but maybe add <nothing>, <deleted>, and union type ({} items)?
There was a problem hiding this comment.
I've added the first two, but don't have time to add the union and tuple ones right now.
| relatively short to avoid overly long error messages. | ||
| def format_bare(self, typ: Type, verbosity: int = 0) -> str: | ||
| """ | ||
| Convert a type to a relatively short string suitable for error messages. |
There was a problem hiding this comment.
Again, an empty line after first line of docstring is needed here.
There was a problem hiding this comment.
Same as before, there is a blank line it's just not considered added for whatever reason.
| Increase the verbosity of the type strings until they become distinct. | ||
| """ | ||
| if bare: | ||
| format_method = self.format_bare |
There was a problem hiding this comment.
Could you please add a comment why we need this more complex logic? Is it only for formatting callable arguments?
There was a problem hiding this comment.
I've expanded the docstring.
| def __aexit__(self, x, y, z) -> int: pass | ||
| async def f() -> None: | ||
| async with C() as x: # E: Incompatible types in "async with" for __aexit__ (actual type "int", expected type Awaitable[Any]) | ||
| async with C() as x: # E: Incompatible types in "async with" for __aexit__ (actual type "int", expected type "Awaitable[Any]") |
There was a problem hiding this comment.
There is still some inconsistency in formatting attribute names here __aexit__ and few lines above "__await__". Would you like to fix this in a separate PR?
There was a problem hiding this comment.
Yep, I suspect these will be more about specific message cleanup than anything else; I'll file an issue with the list of things you've spotted, so I don't lose track of them.
| async def plain_host_coroutine() -> None: | ||
| x = 0 | ||
| x = await plain_generator() # E: Incompatible types in await (actual type Generator[str, None, int], expected type Awaitable[Any]) | ||
| x = await plain_generator() # E: Incompatible types in await (actual type "Generator[str, None, int]", expected type "Awaitable[Any]") |
There was a problem hiding this comment.
Similar situation here: await vs "yield from" few lines above.
There was a problem hiding this comment.
But again, this is a story for a separate PR.
| apply_str(Add5(), 'a') # E: Argument 1 to "apply_str" has incompatible type "Add5"; expected Callable[[str], int] \ | ||
| # N: 'Add5.__call__' has type 'Callable[[Arg(int, 'x')], int]' | ||
| apply_str(Add5(), 'a') # E: Argument 1 to "apply_str" has incompatible type "Add5"; expected "Callable[[str], int]" \ | ||
| # N: 'Add5.__call__' has type "Callable[[Arg(int, 'x')], int]" |
There was a problem hiding this comment.
Another potential idea: maybe use double quotes instead of single quotes in 'Add5.__call__'? (But not in this PR.)
test-data/unit/check-tuples.test
Outdated
| [builtins fixtures/tuple.pyi] | ||
| [out] | ||
| main:3: error: Unsupported operand types for + ("LongTypeName" and tuple(length 50)) | ||
| main:3: error: Unsupported operand types for + ("LongTypeName" and "tuple(length 50)") |
There was a problem hiding this comment.
I think tuple(length 50) should not be surrounded by quotes.
|
@ilevkivskyi So I'm looking at stripping quotes for union types, and the test I'm writing has this output now: but would have: which I find quite hard to parse. (The tuple formatting doesn't have the same problem, because it doesn't repeat the word "type" (it's just I wonder if we should leave the union representation in quotes and then perhaps improve it in a different PR? (I was thinking |
|
(I've pushed up a commit which does it just for tuples for now.) |
|
Actually I like the idea of |
|
\o/ Thanks! |
This is a refreshed version of #3430, and fixes #3409.