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

Add basic support for typing_extensions.TypeVar #14313

Merged
merged 1 commit into from
Dec 19, 2022

Conversation

cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented Dec 19, 2022

This PR only adds the existing TypeVar support for the typing_extensions variant.
I.e. it does not include support for default or infer_variance.

Fixes #14312

@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/types/user.py:45: error: Unexpected argument to "TypeVar()": "default"  [misc]
+ steam/types/user.py:47: error: Unexpected argument to "TypeVar()": "default"  [misc]
+ steam/id.py:222: error: Unexpected argument to "TypeVar()": "default"  [misc]
- steam/role.py:48: error: MemberT? has no attribute "roles"  [attr-defined]
+ steam/app.py:50: error: Unexpected argument to "TypeVar()": "default"  [misc]
+ steam/trade.py:39: error: Unexpected argument to "TypeVar()": "default"  [misc]
+ steam/trade.py:239: error: Unexpected argument to "TypeVar()": "default"  [misc]
+ steam/package.py:37: error: Unexpected argument to "TypeVar()": "default"  [misc]
+ steam/profile.py:77: error: Unexpected argument to "TypeVar()": "default"  [misc]
+ steam/abc.py:53: error: Unexpected argument to "TypeVar()": "default"  [misc]
+ steam/event.py:33: error: Unexpected argument to "TypeVar()": "default"  [misc]
+ steam/event.py:34: error: Unexpected argument to "TypeVar()": "default"  [misc]
+ steam/comment.py:23: error: Unexpected argument to "TypeVar()": "default"  [misc]
- steam/chat.py:130: error: "ChatGroup" expects no type arguments, but 2 given  [type-arg]
+ steam/chat.py:158: error: Unexpected argument to "TypeVar()": "default"  [misc]
- steam/chat.py:178: error: Variable "steam.chat.MemberT" is not valid as a type  [valid-type]
- steam/chat.py:178: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:292: error: Variable "steam.chat.ChatMessageT" is not valid as a type  [valid-type]
- steam/chat.py:292: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:296: error: "ChatGroup" expects no type arguments, but 2 given  [type-arg]
- steam/chat.py:303: error: Variable "steam.chat.ChatMessageT" is not valid as a type  [valid-type]
- steam/chat.py:303: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:340: error: Variable "steam.chat.ChatMessageT" is not valid as a type  [valid-type]
- steam/chat.py:340: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:352: error: Variable "steam.chat.ChatMessageT" is not valid as a type  [valid-type]
- steam/chat.py:352: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:369: error: Variable "steam.chat.ChatMessageT" is not valid as a type  [valid-type]
- steam/chat.py:369: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:372: error: No overload variant of "__new__" of "type" matches argument type "Type[ChatMessageT?]"  [call-overload]
+ steam/chat.py:372: error: No overload variant of "__new__" of "type" matches argument type "Type[ChatMessageT]"  [call-overload]
+ steam/chat.py:422: error: Unexpected argument to "TypeVar()": "default"  [misc]
- steam/chat.py:466: error: Variable "steam.chat.MemberT" is not valid as a type  [valid-type]
- steam/chat.py:466: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:468: error: Variable "steam.chat.ChatT" is not valid as a type  [valid-type]
- steam/chat.py:468: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:522: error: Variable "steam.chat.MemberT" is not valid as a type  [valid-type]
- steam/chat.py:522: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:523: error: Argument 2 to "__get__" of "classproperty" has incompatible type "Type[ChatGroup]"; expected "Type[Self]"  [arg-type]
+ steam/chat.py:523: error: Argument 2 to "__get__" of "classproperty" has incompatible type "Type[ChatGroup[MemberT, ChatT]]"; expected "Type[Self]"  [arg-type]
- steam/chat.py:527: error: Cannot instantiate type "Type[MemberT?]"  [misc]
- steam/chat.py:534: error: Variable "steam.chat.MemberT" is not valid as a type  [valid-type]
- steam/chat.py:534: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:544: error: Argument 2 to "__get__" of "classproperty" has incompatible type "Type[ChatGroup]"; expected "Type[Self]"  [arg-type]
+ steam/chat.py:544: error: Argument 2 to "__get__" of "classproperty" has incompatible type "Type[ChatGroup[MemberT, ChatT]]"; expected "Type[Self]"  [arg-type]
- steam/chat.py:549: error: Cannot instantiate type "Type[ChatT?]"  [misc]
- steam/chat.py:550: error: ChatT? has no attribute "id"  [attr-defined]
- steam/chat.py:552: error: ChatT? has no attribute "_update"  [attr-defined]
- steam/chat.py:578: error: Variable "steam.chat.MemberT" is not valid as a type  [valid-type]
- steam/chat.py:578: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:582: error: Variable "steam.chat.MemberT" is not valid as a type  [valid-type]
- steam/chat.py:582: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:590: note:     def get(self, ID32, /) -> Optional[MemberT?]
+ steam/chat.py:590: note:     def get(self, ID32, /) -> Optional[MemberT]
- steam/chat.py:590: note:     def [_T] get(self, ID32, Union[MemberT?, _T], /) -> Union[MemberT?, _T]
+ steam/chat.py:590: note:     def [_T] get(self, ID32, Union[MemberT, _T], /) -> Union[MemberT, _T]
- steam/chat.py:596: error: Variable "steam.chat.MemberT" is not valid as a type  [valid-type]
- steam/chat.py:596: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:601: error: Variable "steam.chat.MemberT" is not valid as a type  [valid-type]
- steam/chat.py:601: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:608: error: Variable "steam.chat.MemberT" is not valid as a type  [valid-type]
- steam/chat.py:608: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:612: error: Variable "steam.chat.MemberT" is not valid as a type  [valid-type]
- steam/chat.py:612: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:617: error: Variable "steam.chat.MemberT" is not valid as a type  [valid-type]
- steam/chat.py:617: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:622: error: Variable "steam.chat.ChatT" is not valid as a type  [valid-type]
- steam/chat.py:622: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:626: error: Variable "steam.chat.ChatT" is not valid as a type  [valid-type]
- steam/chat.py:626: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:637: error: Variable "steam.chat.ChatT" is not valid as a type  [valid-type]
- steam/chat.py:637: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:667: error: Variable "steam.chat.MemberT" is not valid as a type  [valid-type]
- steam/chat.py:667: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:673: error: Variable "steam.chat.MemberT" is not valid as a type  [valid-type]
- steam/chat.py:673: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/chat.py:691: error: Argument 2 to "__get__" of "classproperty" has incompatible type "Type[ChatGroup]"; expected "Type[Self]"  [arg-type]
+ steam/chat.py:691: error: Argument 2 to "__get__" of "classproperty" has incompatible type "Type[ChatGroup[MemberT, ChatT]]"; expected "Type[Self]"  [arg-type]
- steam/chat.py:693: error: Cannot instantiate type "Type[MemberT?]"  [misc]
+ steam/message.py:29: error: Unexpected argument to "TypeVar()": "default"  [misc]
+ steam/message.py:104: error: Unexpected argument to "TypeVar()": "default"  [misc]
- steam/message.py:109: error: "ChatMessage" expects no type arguments, but 2 given  [type-arg]
+ steam/message.py:109: error: "ChatMessage" expects 1 type argument, but 2 given  [type-arg]
+ steam/message.py:120: error: Unexpected argument to "TypeVar()": "default"  [misc]
- steam/message.py:125: error: "ChatMessage" expects no type arguments, but 2 given  [type-arg]
+ steam/message.py:125: error: "ChatMessage" expects 1 type argument, but 2 given  [type-arg]
- steam/channel.py:171: error: "Chat" expects no type arguments, but 1 given  [type-arg]
- steam/channel.py:197: error: "Chat" expects no type arguments, but 1 given  [type-arg]
- steam/group.py:32: error: "ChatGroup" expects no type arguments, but 3 given  [type-arg]
+ steam/group.py:32: error: "ChatGroup" expects 2 type arguments, but 3 given  [type-arg]
- steam/clan.py:281: error: "ChatGroup" expects no type arguments, but 3 given  [type-arg]
+ steam/clan.py:281: error: "ChatGroup" expects 2 type arguments, but 3 given  [type-arg]
- steam/clan.py:366: error: Incompatible types in assignment (expression has type "Dict[int, ClanChannel]", base class "ChatGroup" defined the type as "Dict[ChatID, ChatT?]")  [assignment]
+ steam/clan.py:366: error: Incompatible types in assignment (expression has type "Dict[int, ClanChannel]", base class "ChatGroup" defined the type as "Dict[ChatID, Any]")  [assignment]
+ steam/bundle.py:23: error: Unexpected argument to "TypeVar()": "default"  [misc]

@cdce8p
Copy link
Collaborator Author

cdce8p commented Dec 19, 2022

The primer output looks as expected, since we don't support default just yet.

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.

Looks good, surprised only one place in the code needed to change. I verified with grep.

@JelleZijlstra JelleZijlstra merged commit 97d9ed5 into python:master Dec 19, 2022
@cdce8p cdce8p deleted the typing_extensions-TypeVar branch December 19, 2022 16:32
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.

typing_extensions TypeVar seems to be unsupported
2 participants