-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Show type aliases in error messages #12835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Show type aliases in error messages #12835
Conversation
Fairly simple change that doesn't completely work for showing type alias names in error messages instead of showing the expanded alias.
As recommended in the docstring for get_proper_type, when you call another function after expanding a type alias, pass the original unexpanded type alias on instead of the expanded version. This tries to fix a few places where we don't follow that in the error formatting code so that unexpanded aliases make it to the error formatting code.
Extend the logic for printing aliases to reuse the logic for printing regular classes. That means that multiple aliases with the same name are printed using their fullname, and generic aliases have their type arguments printed.
If the underlying type that an alias refers to has part of it turned to Any due to an unfollowed import, expand the alias before printing it in the error to make it obvious where the Any actually shows up. We avoid this in the case of the Any due to unfollowed import showing up in the generic arguments, because then the error printing code will clearly print the argument as Any.
Add test to make sure that, in errors about unfollowed imports turning types into Any, we don't expand the alias if the only types turning into Any are in the type arguments, instead of in the underlying type, because then there will be an Any showing up when printing the unexpanded alias.
Fix a lot of tests that had their error messages change due to us printing the alias names instead of the expanded types.
Fix even more tests with aliases in the error messages.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good, thanks! Just few comments below.
Btw I am not sure what do you mean by
Type arguments to generic aliases are printed in some errors, which might get confusing if it isn't obvious what order we're putting the type variables in when determining the list of type arguments.
I think the order should be always the correct one (there are unambiguous rules on this in PEP 484), and we should always print type arguments. Foo
should be never printed instead of Foo[int]
, since Foo
means Foo[Any]
.
@@ -1475,6 +1475,23 @@ def visit_callable_type(self, t: CallableType) -> TypeVarLikeList: | |||
return [] | |||
|
|||
|
|||
def maybe_expand_unimported_type_becomes_any( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH this name is confusing, unimported_type_becomes_any_expanded
would be better IMO. Also, I am not sure this is a best module for this helper. Shouldn't it be in messages.py
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preferred approach would have been adding this code to unimported_type_becomes_any
itself because, like you said, messages.py is a much better place for this than here and I can't really think of a reason you'd want to show that error without using the expanding logic here. The problem is that causes a crash due to an import cycle between typeanal.py and messages.py caused by the use of has_any_from_unimported_type
.
Would it be better to move this into unimported_type_becomes_any
anyway and just work around the crash?
[builtins fixtures/tuple.pyi] | ||
|
||
# See https://github.com/python/mypy/issues/2968#issuecomment-1133768276 | ||
# We need to disable the no_args optimization to get this to work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will have bad performance impact while we still have Text = str
and similar "plain" aliases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's definitely a good point, but I'm not really sure I like the idea of mypy inconsistently showing alias names in error messages based on an implementation detail.
Either way, this PR doesn't actually change that behavior, and leaving the xfail test here seems like a good reminder that we need to discuss whether the performance benefits or consistency is more important (probably in the original issue).
mypy/messages.py
Outdated
"""Return all instances that `t` contains (including `t`). | ||
def collect_all_names(t: Type) -> List[Tuple[str, str]]: | ||
"""Return all (shortname, fullname) pairs for all types that show | ||
up when printing `t` in an error message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docstring is misleading. This function only collects "named" types, like instances and type aliases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the docstring. Could you take a look and see if it's clearer?
Eventually, we probably should update this to include the names of all types that show up when printing the type in an error message, but that seems like something for a different PR.
Would it be possible to show the full names of type aliases, instead of just the shortened names? E.g. show As a typeshed maintainer, I know where (I'm just using Overall, I think this change is a massive usability win! |
Make it clearer that collect_all_names only collects instances and type aliases, not all types that show up in error messages.
Could you clarify where those rules are in PEP 484? I can't find any mention of generic aliases in PEP 484, let alone the order of type arguments for generic aliases.
My main concern with doing that is that it could make some error messages harder to read by making them much longer. Looking at the mypy_primer output, there are a decent number of type aliases where it seems fairly easy to determine what they mean just by looking at the name, and using full names would make those messages much longer. I'd agree that what you're saying is a problem though, so some other ideas are:
We could also try extending some of those options to types defined in any other libraries, but finding the source code and types for a third-party library is easier than finding the types for the standard library due to the special setup, so that seems less urgent. |
Fair point — it does also feel in keeping with mypy's policy in other areas, though. I'm always amused by its steadfast commitment to calling
Agree that this would be a great idea to do anyway. The slight complicating factor is that we may soon be moving some of these types from
If we don't want to always show the full name in type aliases, then this would be my second preference :) |
Diff from mypy_primer, showing the effect of this PR on open source code: paasta (https://github.com/yelp/paasta)
- paasta_tools/metrics/metastatus_lib.py:672: error: Argument "key" to "sorted" has incompatible type "Callable[[Any], Sequence[Tuple[str, str]]]"; expected "Callable[[_SlaveT], Union[SupportsDunderLT, SupportsDunderGT]]"
- paasta_tools/metrics/metastatus_lib.py:672: error: Argument "key" to "sorted" has incompatible type "Callable[[Any], Sequence[Tuple[str, str]]]"; expected "Callable[[Any], Union[SupportsDunderLT, SupportsDunderGT]]"
+ paasta_tools/metrics/metastatus_lib.py:672: error: Argument "key" to "sorted" has incompatible type "_GenericNodeGroupingFunctionT[Any]"; expected "Callable[[_SlaveT], SupportsRichComparison]"
+ paasta_tools/metrics/metastatus_lib.py:672: error: Argument "key" to "sorted" has incompatible type "_GenericNodeGroupingFunctionT[Any]"; expected "Callable[[Any], SupportsRichComparison]"
rclip (https://github.com/yurijmikhalevich/rclip)
- rclip/utils.py:45: error: Argument 1 to "makedirs" has incompatible type "Optional[str]"; expected "Union[str, bytes, PathLike[str], PathLike[bytes]]"
+ rclip/utils.py:45: error: Argument 1 to "makedirs" has incompatible type "Optional[str]"; expected "StrOrBytesPath"
aioredis (https://github.com/aio-libs/aioredis)
- aioredis/client.py:4114: error: Incompatible types in assignment (expression has type "Dict[Union[bytes, str], Optional[Any]]", variable has type "Dict[Union[bytes, str, memoryview], Callable[[Dict[str, str]], Awaitable[None]]]") [assignment]
+ aioredis/client.py:4114: error: Incompatible types in assignment (expression has type "Dict[Union[bytes, str], Optional[Any]]", variable has type "Dict[ChannelT, PubSubHandler]") [assignment]
- aioredis/client.py:4172: error: Incompatible types in assignment (expression has type "Dict[Union[bytes, str, memoryview], Callable[[Dict[str, str]], Awaitable[None]]]", variable has type "Dict[Any, Optional[Any]]") [assignment]
+ aioredis/client.py:4172: error: Incompatible types in assignment (expression has type "Dict[ChannelT, PubSubHandler]", variable has type "Dict[Any, Optional[Any]]") [assignment]
vision (https://github.com/pytorch/vision)
- torchvision/datasets/utils.py:70: error: Argument 1 to "md5" has incompatible type "**Dict[str, bool]"; expected "Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]]" [arg-type]
+ torchvision/datasets/utils.py:70: error: Argument 1 to "md5" has incompatible type "**Dict[str, bool]"; expected "ReadableBuffer" [arg-type]
pip (https://github.com/pypa/pip)
- src/pip/_internal/network/session.py:406: error: Argument 1 to "ip_address" has incompatible type "Optional[str]"; expected "Union[int, str, bytes, IPv4Address, IPv6Address]"
+ src/pip/_internal/network/session.py:406: error: Argument 1 to "ip_address" has incompatible type "Optional[str]"; expected "_RawIPAddress"
cwltool (https://github.com/common-workflow-language/cwltool)
- cwltool/pack.py:323:5: error: Returning Any from function declared to return "MutableMapping[str, Union[bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]]]], None]]" [no-any-return]
+ cwltool/pack.py:323:5: error: Returning Any from function declared to return "MutableMapping[str, Union[bool, str, int, float, MutableSequence[CWLOutputAtomType], MutableMapping[str, CWLOutputAtomType], None]]" [no-any-return]
- cwltool/main.py:337:5: error: Returning Any from function declared to return "MutableMapping[str, Union[bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]], MutableMapping[str, Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]]]], None]]" [no-any-return]
+ cwltool/main.py:337:5: error: Returning Any from function declared to return "MutableMapping[str, Union[bool, str, int, float, MutableSequence[CWLOutputAtomType], MutableMapping[str, CWLOutputAtomType], None]]" [no-any-return]
steam.py (https://github.com/Gobot1234/steam.py)
- steam/image.py:88: error: Argument 1 to "open" has incompatible type "Union[ImageIO, str, bytes, PathLike[str], PathLike[bytes], int]"; expected "Union[Union[str, bytes, PathLike[str], PathLike[bytes]], int]" [arg-type]
+ steam/image.py:88: error: Argument 1 to "open" has incompatible type "Union[ImageIO, str, bytes, PathLike[str], PathLike[bytes], int]"; expected "_OpenFile" [arg-type]
core (https://github.com/home-assistant/core)
- homeassistant/components/simplisafe/__init__.py:256: error: Redundant cast to "Union[Any, Any]" [redundant-cast]
+ homeassistant/components/simplisafe/__init__.py:256: error: Redundant cast to "SystemType" [redundant-cast]
- homeassistant/components/ridwell/sensor.py:93: error: Returning Any from function declared to return "Union[Union[None, str, int, float], date, datetime]" [no-any-return]
+ homeassistant/components/ridwell/sensor.py:93: error: Returning Any from function declared to return "Union[StateType, date, datetime]" [no-any-return]
dragonchain (https://github.com/dragonchain/dragonchain)
- dragonchain/lib/database/redis.py:399:36: error: Argument 2 to "zadd" of "SortedSetCommands" has incompatible type "Dict[str, int]"; expected "Mapping[Union[str, bytes], Union[bytes, float, int, str]]"
+ dragonchain/lib/database/redis.py:399:36: error: Argument 2 to "zadd" of "SortedSetCommands" has incompatible type "Dict[str, int]"; expected "Mapping[_Key, _Value]"
- dragonchain/lib/database/redis_utest.py:102:9: error: "Callable[[Union[str, bytes], Union[bytes, float, int, str], Union[None, int, timedelta], Union[None, int, timedelta], bool, bool, bool, bool, Optional[Any], Optional[Any]], Optional[bool]]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:102:9: error: "Callable[[_Key, _Value, Union[None, int, timedelta], Union[None, int, timedelta], bool, bool, bool, bool, Optional[Any], Optional[Any]], Optional[bool]]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:106:9: error: "Callable[[Union[str, bytes], Union[bytes, float, int, str], Union[None, int, timedelta], Union[None, int, timedelta], bool, bool, bool, bool, Optional[Any], Optional[Any]], Optional[bool]]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:106:9: error: "Callable[[_Key, _Value, Union[None, int, timedelta], Union[None, int, timedelta], bool, bool, bool, bool, Optional[Any], Optional[Any]], Optional[bool]]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:110:9: error: "Callable[[Union[str, bytes]], Optional[Any]]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:110:9: error: "Callable[[_Key], Optional[Any]]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:114:9: error: "Callable[[VarArg(Union[str, bytes])], int]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:114:9: error: "Callable[[VarArg(_Key)], int]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:122:9: error: "Callable[[bool, KwArg(Union[Any, Any])], bool]" has no attribute "assert_called_once"
+ dragonchain/lib/database/redis_utest.py:122:9: error: "Callable[[bool, KwArg(_CommandOptions)], bool]" has no attribute "assert_called_once"
- dragonchain/lib/database/redis_utest.py:126:9: error: "Callable[[Union[str, bytes], VarArg(Union[str, bytes])], int]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:126:9: error: "Callable[[_Key, VarArg(_Key)], int]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:130:9: error: "Callable[[Union[bytes, float, int, str], VarArg(Union[bytes, float, int, str])], int]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:130:9: error: "Callable[[_Value, VarArg(_Value)], int]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:134:9: error: "Callable[[Union[bytes, float, int, str], VarArg(Union[bytes, float, int, str])], int]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:134:9: error: "Callable[[_Value, VarArg(_Value)], int]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:138:9: error: "Callable[[VarArg(Union[str, bytes])], int]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:138:9: error: "Callable[[VarArg(_Key)], int]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:154:9: error: "Callable[[Union[str, bytes]], Optional[Any]]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:154:9: error: "Callable[[_Key], Optional[Any]]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:158:9: error: "Callable[[Union[str, bytes], int], Optional[Any]]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:158:9: error: "Callable[[_Key, int], Optional[Any]]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:162:9: error: "Callable[[Union[str, bytes], Union[bytes, float, int, str], Union[None, int, timedelta], Union[None, int, timedelta], bool, bool, bool, bool, Optional[Any], Optional[Any]], Optional[bool]]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:162:9: error: "Callable[[_Key, _Value, Union[None, int, timedelta], Union[None, int, timedelta], bool, bool, bool, bool, Optional[Any], Optional[Any]], Optional[bool]]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:166:9: error: "Callable[[Union[str, bytes], int, int], bool]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:166:9: error: "Callable[[_Key, int, int], bool]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:170:9: error: "Callable[[Union[str, bytes], Union[str, bytes]], Optional[Any]]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:170:9: error: "Callable[[_Key, _Key], Optional[Any]]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:174:9: error: "Callable[[Union[str, bytes], VarArg(Union[bytes, float, int, str])], int]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:174:9: error: "Callable[[_Key, VarArg(_Value)], int]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:178:9: error: "Callable[[Union[str, bytes], Union[bytes, float, int, str]], bool]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:178:9: error: "Callable[[_Key, _Value], bool]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:182:9: error: "Callable[[Union[str, bytes]], Set[Any]]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:182:9: error: "Callable[[_Key], Set[Any]]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:186:9: error: "Callable[[Union[str, bytes], VarArg(Union[bytes, float, int, str])], int]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:186:9: error: "Callable[[_Key, VarArg(_Value)], int]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:190:9: error: "Callable[[Union[str, bytes], int, int], List[Any]]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:190:9: error: "Callable[[_Key, int, int], List[Any]]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:198:9: error: "Callable[[Union[str, bytes]], int]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:198:9: error: "Callable[[_Key], int]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:210:9: error: "Callable[[Union[str, bytes]], Dict[Any, Any]]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:210:9: error: "Callable[[_Key], Dict[Any, Any]]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:214:9: error: "Callable[[Union[str, bytes], Union[str, bytes]], bool]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:214:9: error: "Callable[[_Key, _Key], bool]" has no attribute "assert_called_once_with"
- dragonchain/lib/database/redis_utest.py:218:9: error: "Callable[[Union[str, bytes], Mapping[Union[str, bytes], Union[bytes, float, int, str]], bool, bool, bool, bool, Optional[Any], Optional[Any]], int]" has no attribute "assert_called_once_with"
+ dragonchain/lib/database/redis_utest.py:218:9: error: "Callable[[_Key, Mapping[_Key, _Value], bool, bool, bool, bool, Optional[Any], Optional[Any]], int]" has no attribute "assert_called_once_with"
Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/context/slash.py:853: note: def respond(self, content: Union[Any, UndefinedType] = ..., *, ensure_result: Literal[True], delete_after: Union[timedelta, float, int, None] = ..., component: Union[ComponentBuilder, UndefinedType] = ..., components: Union[Sequence[ComponentBuilder], UndefinedType] = ..., embed: Union[Embed, UndefinedType] = ..., embeds: Union[Sequence[Embed], UndefinedType] = ..., mentions_everyone: Union[bool, UndefinedType] = ..., user_mentions: Union[Sequence[Union[PartialUser, Union[Snowflake, int]]], bool, UndefinedType] = ..., role_mentions: Union[Sequence[Union[PartialRole, Union[Snowflake, int]]], bool, UndefinedType] = ...) -> Coroutine[Any, Any, Message]
+ tanjun/context/slash.py:853: note: def respond(self, content: UndefinedOr[Any] = ..., *, ensure_result: Literal[True], delete_after: Union[timedelta, float, int, None] = ..., component: UndefinedOr[ComponentBuilder] = ..., components: UndefinedOr[Sequence[ComponentBuilder]] = ..., embed: UndefinedOr[Embed] = ..., embeds: UndefinedOr[Sequence[Embed]] = ..., mentions_everyone: UndefinedOr[bool] = ..., user_mentions: Union[SnowflakeishSequence[PartialUser], bool, UndefinedType] = ..., role_mentions: Union[SnowflakeishSequence[PartialRole], bool, UndefinedType] = ...) -> Coroutine[Any, Any, Message]
- tanjun/context/slash.py:853: note: def respond(self, content: Union[Any, UndefinedType] = ..., *, ensure_result: bool = ..., delete_after: Union[timedelta, float, int, None] = ..., component: Union[ComponentBuilder, UndefinedType] = ..., components: Union[Sequence[ComponentBuilder], UndefinedType] = ..., embed: Union[Embed, UndefinedType] = ..., embeds: Union[Sequence[Embed], UndefinedType] = ..., mentions_everyone: Union[bool, UndefinedType] = ..., user_mentions: Union[Sequence[Union[PartialUser, Union[Snowflake, int]]], bool, UndefinedType] = ..., role_mentions: Union[Sequence[Union[PartialRole, Union[Snowflake, int]]], bool, UndefinedType] = ...) -> Coroutine[Any, Any, Optional[Message]]
+ tanjun/context/slash.py:853: note: def respond(self, content: UndefinedOr[Any] = ..., *, ensure_result: bool = ..., delete_after: Union[timedelta, float, int, None] = ..., component: UndefinedOr[ComponentBuilder] = ..., components: UndefinedOr[Sequence[ComponentBuilder]] = ..., embed: UndefinedOr[Embed] = ..., embeds: UndefinedOr[Sequence[Embed]] = ..., mentions_everyone: UndefinedOr[bool] = ..., user_mentions: Union[SnowflakeishSequence[PartialUser], bool, UndefinedType] = ..., role_mentions: Union[SnowflakeishSequence[PartialRole], bool, UndefinedType] = ...) -> Coroutine[Any, Any, Optional[Message]]
- tanjun/context/slash.py:853: note: def respond(self, content: Union[Any, UndefinedType] = ..., *, ensure_result: Literal[False] = ..., delete_after: Union[timedelta, float, int, None] = ..., component: Union[ComponentBuilder, UndefinedType] = ..., components: Union[Sequence[ComponentBuilder], UndefinedType] = ..., embed: Union[Embed, UndefinedType] = ..., embeds: Union[Sequence[Embed], UndefinedType] = ..., mentions_everyone: Union[bool, UndefinedType] = ..., user_mentions: Union[Sequence[Union[PartialUser, Union[Snowflake, int]]], bool, UndefinedType] = ..., role_mentions: Union[Sequence[Union[PartialRole, Union[Snowflake, int]]], bool, UndefinedType] = ...) -> Coroutine[Any, Any, Optional[Message]]
+ tanjun/context/slash.py:853: note: def respond(self, content: UndefinedOr[Any] = ..., *, ensure_result: Literal[False] = ..., delete_after: Union[timedelta, float, int, None] = ..., component: UndefinedOr[ComponentBuilder] = ..., components: UndefinedOr[Sequence[ComponentBuilder]] = ..., embed: UndefinedOr[Embed] = ..., embeds: UndefinedOr[Sequence[Embed]] = ..., mentions_everyone: UndefinedOr[bool] = ..., user_mentions: Union[SnowflakeishSequence[PartialUser], bool, UndefinedType] = ..., role_mentions: Union[SnowflakeishSequence[PartialRole], bool, UndefinedType] = ...) -> Coroutine[Any, Any, Optional[Message]]
- tanjun/context/slash.py:853: note: def respond(self, content: Union[Any, UndefinedType] = ..., *, ensure_result: Literal[True], delete_after: Union[timedelta, float, int, None] = ..., component: Union[ComponentBuilder, UndefinedType] = ..., components: Union[Sequence[ComponentBuilder], UndefinedType] = ..., embed: Union[Embed, UndefinedType] = ..., embeds: Union[Sequence[Embed], UndefinedType] = ..., mentions_everyone: Union[bool, UndefinedType] = ..., user_mentions: Union[Sequence[Union[PartialUser, Union[Snowflake, int]]], bool, UndefinedType] = ..., role_mentions: Union[Sequence[Union[PartialRole, Union[Snowflake, int]]], bool, UndefinedType] = ...) -> Coroutine[Any, Any, Message]
+ tanjun/context/slash.py:853: note: def respond(self, content: UndefinedOr[Any] = ..., *, ensure_result: Literal[True], delete_after: Union[timedelta, float, int, None] = ..., component: UndefinedOr[ComponentBuilder] = ..., components: UndefinedOr[Sequence[ComponentBuilder]] = ..., embed: UndefinedOr[Embed] = ..., embeds: UndefinedOr[Sequence[Embed]] = ..., mentions_everyone: UndefinedOr[bool] = ..., user_mentions: Union[SnowflakeishSequence[PartialUser], bool, UndefinedType] = ..., role_mentions: Union[SnowflakeishSequence[PartialRole], bool, UndefinedType] = ...) -> Coroutine[Any, Any, Message]
|
Description
This PR adds initial support for showing type aliases in error messages, which involves a few different parts:
Any
due to unfollowed imports if the type becomingAny
was in the original aliased typeAs mentioned in #2968 (comment), there's still more work to do on showing type aliases in error messages, but I think this is a good start.
Works on #2968
Other notes about this PR:
reveal_type
still expands out aliases when printing, so I think this should be fine since the full type is fairly straightforward to access.Test Plan
I added a few tests to the bottom of check-type-aliases.test, and I checked that the changes necessary for the other tests seemed to look reasonable.