Extracted from #6460
Say you have
lx: Optional[Tuple[str, int]] = None
lx[0]
reveal_type(lx)
mypy outputs
Value of type "Optional[Tuple[str, int]]" is not indexable
Revealed type is 'Union[Tuple[builtins.str, builtins.int], None]'
As you can see (and probably know) it shows two different representations for the inferred type. For user ergonomics the revealed type should be 'Optional[Tuple[int, str]]' as well, no?
The maybe too naive but works for me change is
@@ -1051,7 +1051,7 @@ class MessageBuilder:
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.fail('Revealed type is {}'.format(self.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,
But then you get 1.000.000 failures which is expected because the tests rely on the verbose output.
E.g.
Expected:
main:10: error: Revealed type is 'builtins.int' (diff)
main:11: error: Revealed type is 'Tuple[builtins.int, builtins.int]' (diff)
main:13: error: Revealed type is 'Literal[1]' (diff)
main:14: error: Argument 1 to "force2" has incompatible type "Tuple[int, in...
main:14: error: Revealed type is 'Tuple[builtins.int, builtins.int]' (diff)
Actual:
main:10: error: Revealed type is "int" (diff)
main:11: error: Revealed type is "Tuple[int, int]" (diff)
main:13: error: Revealed type is "Literal[1]" (diff)
main:14: error: Argument 1 to "force2" has incompatible type "Tuple[int, in...
main:14: error: Revealed type is "Tuple[int, int]" (diff)
This makes it a non-trivial change.
Extracted from #6460
Say you have
mypy outputs
As you can see (and probably know) it shows two different representations for the inferred type. For user ergonomics the revealed type should be 'Optional[Tuple[int, str]]' as well, no?
The maybe too naive but works for me change is
But then you get 1.000.000 failures which is expected because the tests rely on the verbose output.
E.g.
This makes it a non-trivial change.