Skip to content
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

Coalesce Literals when printing Unions #12205

Merged
merged 9 commits into from Feb 20, 2022

Conversation

intgr
Copy link
Contributor

@intgr intgr commented Feb 17, 2022

Description

  • check if there are open issues that this solves.

Error messages containing literals are currently very unwieldly. This is an attempt to change that, instead of Union[Literal[X], Literal[Y]], they are now printed as Literal[X, Y].

Before After
Union[Literal['a'], Literal['b']] Literal['a', 'b']
Union[Literal['a'], Literal['b'], None] Optional[Literal['a', 'b']]
Union[Literal['a'], Literal['b'], int] Union[int, Literal['a', 'b']]
Union[Literal['a'], Literal['b'], None, int] Union[None, int, Literal['a', 'b']]

The order of original Union members is not preserved if there are multiple Literal members: Literal members are moved to the end. But I could change this to attempt preserving the order.

Before After
Union[Literal['a'], Literal['b'], int] Union[int, Literal['a', 'b']]
Union[Literal['a'], int] Union[Literal['a'], int]

Test Plan

Lots of coverage for this already in the test suite, see test file diffs.

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I don't remember seeing an issue about this.

I implemented something similar in pyanalyze: https://github.com/quora/pyanalyze/blob/master/pyanalyze/value.py#L1461
One difference is that I format Union[None, Literal[1], Literal[2]] as Literal[None, 1, 2] but you chose Optional[Literal[1, 2]]. I think either is fine though.

@github-actions

This comment has been minimized.

Copy link
Collaborator

@97littleleaf11 97littleleaf11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for you PR! I like this feature that makes union of literal types much neater. I have one suggestion.

mypy/sametypes.py Outdated Show resolved Hide resolved
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Also, take a look at this message:

steam/client.py:504: error: Argument "type" to "make_id64" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]]" [arg-type]

Optional[Union[...]]

Maybe you will also like to improve it in the next PR?

@intgr
Copy link
Contributor Author

intgr commented Feb 19, 2022

Pushed a few changes:

  • Moved the helper function to typeops.py
  • The new logic now only triggers if there are multiple Literal[] members. If there's just one Literal member, the order is preserved.
  • Restored formatting of enum literals.

This should now be ready.

@intgr intgr marked this pull request as ready for review February 19, 2022 11:36
@github-actions

This comment has been minimized.

2 similar comments
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

steam.py (https://github.com/Gobot1234/steam.py)
- steam/utils.py:148: error: Incompatible types in assignment (expression has type "Union[Literal['Invalid'], Literal['Individual'], Literal['Multiseat'], Literal['GameServer'], Literal['AnonGameServer'], Literal['Pending'], Literal['ContentServer'], Literal['Clan'], Literal['Chat'], Literal['ConsoleUser'], Literal['AnonUser'], Literal['Max'], int]", variable has type "Optional[Union[Type, Literal['Invalid'], Literal['Individual'], Literal['Multiseat'], Literal['GameServer'], Literal['AnonGameServer'], Literal['Pending'], Literal['ContentServer'], Literal['Clan'], Literal['Chat'], Literal['ConsoleUser'], Literal['AnonUser'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6], Literal[7], Literal[8], Literal[9], Literal[10], Literal[11]]]")  [assignment]
- steam/utils.py:149: error: Incompatible types in assignment (expression has type "Union[Literal['Invalid'], Literal['Public'], Literal['Beta'], Literal['Internal'], Literal['Dev'], Literal['Max'], int]", variable has type "Optional[Union[Universe, Literal['Invalid'], Literal['Public'], Literal['Beta'], Literal['Internal'], Literal['Dev'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6]]]")  [assignment]
+ steam/utils.py:148: error: Incompatible types in assignment (expression has type "Union[int, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max']]", variable has type "Optional[Union[Type, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]]")  [assignment]
+ steam/utils.py:149: error: Incompatible types in assignment (expression has type "Union[int, Literal['Invalid', 'Public', 'Beta', 'Internal', 'Dev', 'Max']]", variable has type "Optional[Union[Universe, Literal['Invalid', 'Public', 'Beta', 'Internal', 'Dev', 'Max', 0, 1, 2, 3, 4, 5, 6]]]")  [assignment]
- steam/utils.py:154: error: Incompatible types in assignment (expression has type "int", variable has type "Optional[Union[Literal[0], Literal[1], Literal[2], Literal[4]]]")  [assignment]
+ steam/utils.py:154: error: Incompatible types in assignment (expression has type "int", variable has type "Optional[Literal[0, 1, 2, 4]]")  [assignment]
- steam/utils.py:155: error: Incompatible types in assignment (expression has type "int", variable has type "Optional[Union[Type, Literal['Invalid'], Literal['Individual'], Literal['Multiseat'], Literal['GameServer'], Literal['AnonGameServer'], Literal['Pending'], Literal['ContentServer'], Literal['Clan'], Literal['Chat'], Literal['ConsoleUser'], Literal['AnonUser'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6], Literal[7], Literal[8], Literal[9], Literal[10], Literal[11]]]")  [assignment]
- steam/utils.py:156: error: Incompatible types in assignment (expression has type "int", variable has type "Optional[Union[Universe, Literal['Invalid'], Literal['Public'], Literal['Beta'], Literal['Internal'], Literal['Dev'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6]]]")  [assignment]
+ steam/utils.py:155: error: Incompatible types in assignment (expression has type "int", variable has type "Optional[Union[Type, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]]")  [assignment]
+ steam/utils.py:156: error: Incompatible types in assignment (expression has type "int", variable has type "Optional[Union[Universe, Literal['Invalid', 'Public', 'Beta', 'Internal', 'Dev', 'Max', 0, 1, 2, 3, 4, 5, 6]]]")  [assignment]
- steam/utils.py:161: error: Argument 1 to "Type" has incompatible type "Union[Type, Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6], Literal[7], Literal[8], Literal[9], Literal[10], Literal[11]]"; expected "str"  [arg-type]
+ steam/utils.py:161: error: Argument 1 to "Type" has incompatible type "Union[Type, Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]"; expected "str"  [arg-type]
- steam/utils.py:165: error: Argument 1 to "Universe" has incompatible type "Union[Universe, Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6]]"; expected "str"  [arg-type]
+ steam/utils.py:165: error: Argument 1 to "Universe" has incompatible type "Union[Universe, Literal[0, 1, 2, 3, 4, 5, 6]]"; expected "str"  [arg-type]
- steam/utils.py:172: note: Left operand is of type "Optional[Union[Universe, Literal['Invalid'], Literal['Public'], Literal['Beta'], Literal['Internal'], Literal['Dev'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6]]]"
+ steam/utils.py:172: note: Left operand is of type "Optional[Union[Universe, Literal['Invalid', 'Public', 'Beta', 'Internal', 'Dev', 'Max', 0, 1, 2, 3, 4, 5, 6]]]"
- steam/utils.py:172: note: Left operand is of type "Optional[Union[Type, Literal['Invalid'], Literal['Individual'], Literal['Multiseat'], Literal['GameServer'], Literal['AnonGameServer'], Literal['Pending'], Literal['ContentServer'], Literal['Clan'], Literal['Chat'], Literal['ConsoleUser'], Literal['AnonUser'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6], Literal[7], Literal[8], Literal[9], Literal[10], Literal[11]]]"
+ steam/utils.py:172: note: Left operand is of type "Optional[Union[Type, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]]"
- steam/game_server.py:413: error: Argument "type" to "__init__" of "SteamID" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid'], Literal['Individual'], Literal['Multiseat'], Literal['GameServer'], Literal['AnonGameServer'], Literal['Pending'], Literal['ContentServer'], Literal['Clan'], Literal['Chat'], Literal['ConsoleUser'], Literal['AnonUser'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6], Literal[7], Literal[8], Literal[9], Literal[10], Literal[11]]]"  [arg-type]
+ steam/game_server.py:413: error: Argument "type" to "__init__" of "SteamID" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]]"  [arg-type]
- steam/group.py:93: error: Argument "type" to "__init__" of "SteamID" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid'], Literal['Individual'], Literal['Multiseat'], Literal['GameServer'], Literal['AnonGameServer'], Literal['Pending'], Literal['ContentServer'], Literal['Clan'], Literal['Chat'], Literal['ConsoleUser'], Literal['AnonUser'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6], Literal[7], Literal[8], Literal[9], Literal[10], Literal[11]]]"  [arg-type]
+ steam/group.py:93: error: Argument "type" to "__init__" of "SteamID" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]]"  [arg-type]
- steam/clan.py:159: error: Argument "type" to "__init__" of "SteamID" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid'], Literal['Individual'], Literal['Multiseat'], Literal['GameServer'], Literal['AnonGameServer'], Literal['Pending'], Literal['ContentServer'], Literal['Clan'], Literal['Chat'], Literal['ConsoleUser'], Literal['AnonUser'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6], Literal[7], Literal[8], Literal[9], Literal[10], Literal[11]]]"  [arg-type]
- steam/clan.py:180: error: Argument "type" to "__init__" of "SteamID" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid'], Literal['Individual'], Literal['Multiseat'], Literal['GameServer'], Literal['AnonGameServer'], Literal['Pending'], Literal['ContentServer'], Literal['Clan'], Literal['Chat'], Literal['ConsoleUser'], Literal['AnonUser'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6], Literal[7], Literal[8], Literal[9], Literal[10], Literal[11]]]"  [arg-type]
+ steam/clan.py:159: error: Argument "type" to "__init__" of "SteamID" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]]"  [arg-type]
+ steam/clan.py:180: error: Argument "type" to "__init__" of "SteamID" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]]"  [arg-type]
- steam/client.py:504: error: Argument "type" to "make_id64" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid'], Literal['Individual'], Literal['Multiseat'], Literal['GameServer'], Literal['AnonGameServer'], Literal['Pending'], Literal['ContentServer'], Literal['Clan'], Literal['Chat'], Literal['ConsoleUser'], Literal['AnonUser'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6], Literal[7], Literal[8], Literal[9], Literal[10], Literal[11]]]"  [arg-type]
- steam/client.py:516: error: Argument "type" to "make_id64" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid'], Literal['Individual'], Literal['Multiseat'], Literal['GameServer'], Literal['AnonGameServer'], Literal['Pending'], Literal['ContentServer'], Literal['Clan'], Literal['Chat'], Literal['ConsoleUser'], Literal['AnonUser'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6], Literal[7], Literal[8], Literal[9], Literal[10], Literal[11]]]"  [arg-type]
- steam/client.py:531: error: Argument "type" to "make_id64" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid'], Literal['Individual'], Literal['Multiseat'], Literal['GameServer'], Literal['AnonGameServer'], Literal['Pending'], Literal['ContentServer'], Literal['Clan'], Literal['Chat'], Literal['ConsoleUser'], Literal['AnonUser'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6], Literal[7], Literal[8], Literal[9], Literal[10], Literal[11]]]"  [arg-type]
- steam/client.py:574: error: Argument "type" to "SteamID" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid'], Literal['Individual'], Literal['Multiseat'], Literal['GameServer'], Literal['AnonGameServer'], Literal['Pending'], Literal['ContentServer'], Literal['Clan'], Literal['Chat'], Literal['ConsoleUser'], Literal['AnonUser'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6], Literal[7], Literal[8], Literal[9], Literal[10], Literal[11]]]"  [arg-type]
- steam/client.py:586: error: Argument "type" to "SteamID" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid'], Literal['Individual'], Literal['Multiseat'], Literal['GameServer'], Literal['AnonGameServer'], Literal['Pending'], Literal['ContentServer'], Literal['Clan'], Literal['Chat'], Literal['ConsoleUser'], Literal['AnonUser'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6], Literal[7], Literal[8], Literal[9], Literal[10], Literal[11]]]"  [arg-type]
- steam/client.py:598: error: Argument "type" to "make_id64" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid'], Literal['Individual'], Literal['Multiseat'], Literal['GameServer'], Literal['AnonGameServer'], Literal['Pending'], Literal['ContentServer'], Literal['Clan'], Literal['Chat'], Literal['ConsoleUser'], Literal['AnonUser'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6], Literal[7], Literal[8], Literal[9], Literal[10], Literal[11]]]"  [arg-type]
- steam/client.py:680: error: Argument "type" to "make_id64" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid'], Literal['Individual'], Literal['Multiseat'], Literal['GameServer'], Literal['AnonGameServer'], Literal['Pending'], Literal['ContentServer'], Literal['Clan'], Literal['Chat'], Literal['ConsoleUser'], Literal['AnonUser'], Literal['Max'], Literal[0], Literal[1], Literal[2], Literal[3], Literal[4], Literal[5], Literal[6], Literal[7], Literal[8], Literal[9], Literal[10], Literal[11]]]"  [arg-type]
+ steam/client.py:504: error: Argument "type" to "make_id64" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]]"  [arg-type]
+ steam/client.py:516: error: Argument "type" to "make_id64" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]]"  [arg-type]
+ steam/client.py:531: error: Argument "type" to "make_id64" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]]"  [arg-type]
+ steam/client.py:574: error: Argument "type" to "SteamID" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]]"  [arg-type]
+ steam/client.py:586: error: Argument "type" to "SteamID" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]]"  [arg-type]
+ steam/client.py:598: error: Argument "type" to "make_id64" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]]"  [arg-type]
+ steam/client.py:680: error: Argument "type" to "make_id64" has incompatible type "int"; expected "Optional[Union[Type, Literal['Invalid', 'Individual', 'Multiseat', 'GameServer', 'AnonGameServer', 'Pending', 'ContentServer', 'Clan', 'Chat', 'ConsoleUser', 'AnonUser', 'Max', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]]"  [arg-type]
- steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Union[Literal['connect'], Literal['disconnect'], Literal['ready'], Literal['login'], Literal['logout']], *, check: Callable[[], bool] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, None]
+ steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Literal['connect', 'disconnect', 'ready', 'login', 'logout'], *, check: Callable[[], bool] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, None]
- steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Union[Literal['trade_receive'], Literal['trade_send'], Literal['trade_accept'], Literal['trade_decline'], Literal['trade_cancel'], Literal['trade_expire'], Literal['trade_counter']], *, check: Callable[[TradeOffer], bool] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, TradeOffer]
+ steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Literal['trade_receive', 'trade_send', 'trade_accept', 'trade_decline', 'trade_cancel', 'trade_expire', 'trade_counter'], *, check: Callable[[TradeOffer], bool] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, TradeOffer]
- steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Union[Literal['user_invite'], Literal['user_invite_accept'], Literal['user_invite_decline']], *, check: Callable[[UserInvite], bool] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, UserInvite]
+ steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Literal['user_invite', 'user_invite_accept', 'user_invite_decline'], *, check: Callable[[UserInvite], bool] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, UserInvite]
- steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Union[Literal['clan_invite'], Literal['clan_invite_accept'], Literal['clan_invite_decline']], *, check: Callable[[ClanInvite], bool] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, ClanInvite]
+ steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Literal['clan_invite', 'clan_invite_accept', 'clan_invite_decline'], *, check: Callable[[ClanInvite], bool] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, ClanInvite]
- steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Union[Literal['clan_join'], Literal['clan_leave']], *, check: Callable[[Clan], bool] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, Clan]
+ steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Literal['clan_join', 'clan_leave'], *, check: Callable[[Clan], bool] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, Clan]
- steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Union[Literal['group_join'], Literal['group_leave']], *, check: Callable[[Group], bool] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, Group]
+ steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Literal['group_join', 'group_leave'], *, check: Callable[[Group], bool] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, Group]
- steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Union[Literal['socket_receive'], Literal['socket_send']], *, check: Callable[[Any], bool] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, Any]
+ steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Literal['socket_receive', 'socket_send'], *, check: Callable[[Any], bool] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, Any]
- steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Union[Literal['connect'], Literal['disconnect'], Literal['ready'], Literal['login'], Literal['logout']], *, check: Optional[Callable[[], bool]] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, None]
+ steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Literal['connect', 'disconnect', 'ready', 'login', 'logout'], *, check: Optional[Callable[[], bool]] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, None]
- steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Union[Literal['trade_receive'], Literal['trade_send'], Literal['trade_accept'], Literal['trade_decline'], Literal['trade_cancel'], Literal['trade_expire'], Literal['trade_counter']], *, check: Optional[Callable[[TradeOffer], bool]] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, TradeOffer]
+ steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Literal['trade_receive', 'trade_send', 'trade_accept', 'trade_decline', 'trade_cancel', 'trade_expire', 'trade_counter'], *, check: Optional[Callable[[TradeOffer], bool]] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, TradeOffer]
- steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Union[Literal['socket_receive'], Literal['socket_send']], *, check: Optional[Callable[[Union[Union[MsgProto[Any], Msg[Any]], Union[GCMsgProto[Any], GCMsg[Any]]]], bool]] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, Union[Union[MsgProto[Any], Msg[Any]], Union[GCMsgProto[Any], GCMsg[Any]]]]
+ steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Literal['socket_receive', 'socket_send'], *, check: Optional[Callable[[Union[Union[MsgProto[Any], Msg[Any]], Union[GCMsgProto[Any], GCMsg[Any]]]], bool]] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, Union[Union[MsgProto[Any], Msg[Any]], Union[GCMsgProto[Any], GCMsg[Any]]]]
- steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Union[Literal['command'], Literal['command_completion']], *, check: Optional[Callable[[Context], bool]] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, Context]
+ steam/ext/commands/bot.py:671: note:          def wait_for(self, event: Literal['command', 'command_completion'], *, check: Optional[Callable[[Context], bool]] = ..., timeout: Optional[float] = ...) -> Coroutine[Any, Any, Context]

Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/clients.py:1210: error: Argument 2 to "create_context_menu_command" of "RESTClient" has incompatible type "Union[CommandType, UndefinedType]"; expected "Union[Literal[CommandType.USER], Literal[CommandType.MESSAGE], Literal[2], Literal[3]]"  [arg-type]
+ tanjun/clients.py:1210: error: Argument 2 to "create_context_menu_command" of "RESTClient" has incompatible type "Union[CommandType, UndefinedType]"; expected "Literal[CommandType.USER, CommandType.MESSAGE, 2, 3]"  [arg-type]

Copy link
Collaborator

@97littleleaf11 97littleleaf11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think current PR is good enough to merge! The Optional[Union[]] is an existing issue and you can create a separate PR as @sobolevn suggested.

@97littleleaf11
Copy link
Collaborator

btw, I remember that I once saw an issue related to this feature. But I can't find it right now.

@intgr
Copy link
Contributor Author

intgr commented Feb 19, 2022

I tried finding issues related to this, went through a few pages, but turned up empty. But it's possible I wasn't using the right search keywords.

@97littleleaf11
Copy link
Collaborator

I tried finding issues related to this, went through a few pages, but turned up empty

It doesn't matter. Someone can close it in the future if it does exist.

@sobolevn sobolevn merged commit 68b208d into python:master Feb 20, 2022
@sobolevn
Copy link
Member

Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants