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

Update semantic analyzer for TypeVar defaults (PEP 696) #14873

Merged
merged 4 commits into from
Jun 6, 2023

Conversation

cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented Mar 11, 2023

This PR updates the semantic analyzer to support most forms of TypeVars with defaults while also providing basic argument validation.

Ref: #14851

@cdce8p cdce8p marked this pull request as draft March 11, 2023 12:06
@github-actions

This comment has been minimized.

@cdce8p cdce8p force-pushed the TypeVar-02-basic-validation branch from 10da8e7 to ef479c6 Compare March 12, 2023 14:49
@github-actions

This comment has been minimized.

@cdce8p cdce8p force-pushed the TypeVar-02-basic-validation branch from ef479c6 to eb7ba73 Compare April 3, 2023 10:38
@github-actions

This comment has been minimized.

@cdce8p cdce8p force-pushed the TypeVar-02-basic-validation branch from eb7ba73 to f8e8f66 Compare April 16, 2023 06:51
@github-actions

This comment has been minimized.

@cdce8p cdce8p force-pushed the TypeVar-02-basic-validation branch from f8e8f66 to e8bbe5c Compare May 2, 2023 09:02
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@cdce8p cdce8p force-pushed the TypeVar-02-basic-validation branch from a6ee900 to 575f772 Compare May 7, 2023 09:35
@github-actions

This comment has been minimized.

@cdce8p cdce8p force-pushed the TypeVar-02-basic-validation branch from 575f772 to 0ea018e Compare May 29, 2023 22:22
@github-actions

This comment has been minimized.

JelleZijlstra pushed a commit that referenced this pull request May 29, 2023
Start implementing [PEP 696](https://peps.python.org/pep-0696/) TypeVar
defaults. This PR
* Adds a `default` parameter to `TypeVarLikeExpr` and `TypeVarLikeType`.
* Updates most visitors to account for the new `default` parameter.
* Update existing calls to add value for `default` =>
`AnyType(TypeOfAny.from_omitted_generics)`.

A followup PR will update the semantic analyzer and add basic tests for
`TypeVar`, `ParamSpec`, and `TypeVarTuple` calls with a `default`
argument. -> #14873

Ref #14851
mypy/semanal.py Outdated
param_value,
)
# Note: we do not return 'None' here -- we want to continue
# using the AnyType as the upper bound.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# using the AnyType as the upper bound.
# using the AnyType.

Or the default

mypy/semanal.py Outdated
self.fail("Only the first argument to ParamSpec has defined semantics", s)
n_values = call.arg_kinds[1:].count(ARG_POS)
if n_values != 0:
self.fail("Only the first positional argument to ParamSpec has defined semantics", s)
Copy link
Member

Choose a reason for hiding this comment

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

It actually only takes one positional arg, the rest are keyword-only. So this error message seems imprecise; I think we can just say "Too many positional arguments to ParamSpec()"

mypy/semanal.py Outdated
default = AnyType(TypeOfAny.from_error)
else:
self.fail(
"The variance and bound arguments to TypeVarTuple do not have defined semantics yet",
Copy link
Member

Choose a reason for hiding this comment

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

And in fact they do not exist at runtime

@JelleZijlstra JelleZijlstra added the topic-pep-696 TypeVar defaults label May 29, 2023
@cdce8p cdce8p force-pushed the TypeVar-02-basic-validation branch from 8622a58 to d6e39c4 Compare May 30, 2023 00:01
@cdce8p
Copy link
Collaborator Author

cdce8p commented May 30, 2023

Rebased to fix the tests. The merge created two duplicate lines which caused the failures. Will take a look at the comments tomorrow.

@github-actions

This comment has been minimized.

@JelleZijlstra JelleZijlstra self-requested a review May 30, 2023 17:38
@JelleZijlstra
Copy link
Member

@cdce8p if you're happy with this PR now, feel free to take it out of draft and I'll review it.

Maybe we should put this behind an --enable-incomplete-feature for now?

@github-actions

This comment has been minimized.

@cdce8p cdce8p marked this pull request as ready for review May 30, 2023 17:55
@cdce8p
Copy link
Collaborator Author

cdce8p commented May 30, 2023

@cdce8p if you're happy with this PR now, feel free to take it out of draft and I'll review it.

Maybe we should put this behind an --enable-incomplete-feature for now?

The PR itself is fine. I'm just checking the primer output one more time to make sure but so far I looks as expected. The important thing to note is that these changes don't impact projects which haven't started using PEP 696 yet. For steam and discord I would expect changes / improvements as support for default is added.

Will post a more detailed update regarding the primer output shortly.

As for --enable-incomplete-feature I thought about this as well. It might make sense to wait a bit and see how far we'll get with the support. If it's still unusable when the next release is due, we can still add it. However, ideally no of the changes for PEP 696 should impact existing code. So not sure it's really necessary.

@cdce8p
Copy link
Collaborator Author

cdce8p commented May 30, 2023

Primer analysis
Both steam and discord make heavy use of default=... already which explains the number of errors.

  1. TypeVar, ParamSpec aren't rejected anymore just because they contain default.
- discord/_types.py:32: error: Unexpected argument to "TypeVar()": "default"  [misc]
- discord/_types.py:32: error: Unexpected keyword argument "default" for "TypeVar"  [call-arg]
- discord/state.py:1617: error: "ConnectionState" expects no type arguments, but 1 given  [type-arg]
- discord/state.py:163: error: Free type variable expected in Generic[...]  [misc]
- discord/state.py:166: error: Variable "discord._types.ClientT" is not valid as a type  [valid-type]
- discord/state.py:166: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- discord/state.py:166: error: Variable "discord._types.ClientT" is not valid as a type  [valid-type]
- discord/state.py:166: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
  1. attr-defined errors disappear since bound can now be used again to infer the base type
- discord/app_commands/tree.py:128: error: ClientT? has no attribute "http"  [attr-defined]
  1. A lot of error messages just add a new generic parameter
- discord/interactions.py:255: error: Incompatible return value type (got "ConnectionState | Guild | None", expected "Guild | None")  [return-value]
+ discord/interactions.py:255: error: Incompatible return value type (got "ConnectionState[ClientT] | Guild | None", expected "Guild | None")  [return-value]
  1. The default values isn't actually used yet which results in a few new errors
+ steam/id.py:576: error: Need type annotation for "id"  [var-annotated]
+ steam/app.py:94: error: Incompatible default for argument "name" (default has type "None", argument has type "NameT")  [assignment]

Overall the result looks as expected and should improve further once the default value is actually applied / used.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 6, 2023

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:137: error: Unexpected argument to "TypeVar()": "default"  [misc]
- steam/types/user.py:139: error: Unexpected argument to "TypeVar()": "default"  [misc]
- steam/types/user.py:142: error: "ID" expects no type arguments, but 1 given  [type-arg]
- steam/id.py:223: error: Unexpected argument to "TypeVar()": "default"  [misc]
- steam/id.py:226: error: Free type variable expected in Generic[...]  [misc]
- steam/id.py:294: error: Variable "steam.id.TypeT" is not valid as a type  [valid-type]
- steam/id.py:294: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/id.py:331: error: Variable "steam.id.TypeT" is not valid as a type  [valid-type]
- steam/id.py:331: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/id.py:333: error: Variable "steam.id.TypeT" is not valid as a type  [valid-type]
- steam/id.py:333: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/id.py:546: error: "ID" expects no type arguments, but 1 given  [type-arg]
- steam/id.py:567: error: "ID" expects no type arguments, but 1 given  [type-arg]
- steam/id.py:581: error: The type "type[ID]" is not generic and not indexable  [misc]
+ steam/id.py:576: error: Need type annotation for "id"  [var-annotated]
+ steam/id.py:581: error: Parameter 1 of Literal[...] is invalid  [valid-type]
+ steam/badge.py:123: error: Argument 1 to "inventory" of "PartialUser" has incompatible type "tuple[str, int, int]"; expected "App[Any]"  [arg-type]
+ steam/badge.py:185: error: Argument 4 to "__init__" of "BaseOwnedBadge" has incompatible type "object"; expected "PartialApp[Any]"  [arg-type]
+ steam/app.py:94: error: Incompatible default for argument "name" (default has type "None", argument has type "NameT")  [assignment]
+ steam/app.py:94: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
+ steam/app.py:94: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
+ steam/app.py:116: error: Incompatible return value type (got "NameT | str", expected "str")  [return-value]
+ steam/app.py:129: error: Argument "game_extra_info" to "CMsgClientGamesPlayedGamePlayed" has incompatible type "NameT"; expected "str"  [arg-type]
+ steam/app.py:195: error: Need type annotation for "app"  [var-annotated]
+ steam/app.py:207: error: Need type annotation for "licenses"  [var-annotated]
- steam/role.py:64: error: MemberT? has no attribute "roles"  [attr-defined]
- steam/badge.py:29: error: Unexpected argument to "TypeVar()": "default"  [misc]
- steam/badge.py:40: error: Variable "steam.badge.AppT" is not valid as a type  [valid-type]
- steam/badge.py:40: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/badge.py:43: error: Variable "steam.badge.AppT" is not valid as a type  [valid-type]
- steam/badge.py:43: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/badge.py:56: error: Unsupported left operand type for == (AppT?)  [operator]
- steam/badge.py:66: error: AppT? has no attribute "badges"  [attr-defined]
- steam/badge.py:73: error: AppT? has no attribute "badges"  [attr-defined]
- steam/badge.py:79: error: "BaseBadge" expects no type arguments, but 1 given  [type-arg]
- steam/badge.py:79: error: Variable "steam.badge.AppT" is not valid as a type  [valid-type]
- steam/badge.py:79: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/badge.py:84: error: Variable "steam.badge.AppT" is not valid as a type  [valid-type]
- steam/badge.py:84: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/badge.py:102: error: Variable "steam.types.user.UserT" is not valid as a type  [valid-type]
- steam/badge.py:102: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/badge.py:111: error: Variable "steam.badge.AppT" is not valid as a type  [valid-type]
- steam/badge.py:111: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/badge.py:111: error: Variable "steam.types.user.UserT" is not valid as a type  [valid-type]
- steam/badge.py:117: error: "Item" expects no type arguments, but 1 given  [type-arg]
- steam/badge.py:117: error: Variable "steam.types.user.UserT" is not valid as a type  [valid-type]
- steam/badge.py:117: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/badge.py:123: error: UserT? has no attribute "inventory"  [attr-defined]
- steam/badge.py:129: error: "Item" expects no type arguments, but 1 given  [type-arg]
- steam/badge.py:129: error: Variable "steam.types.user.UserT" is not valid as a type  [valid-type]
- steam/badge.py:129: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/badge.py:139: error: "Item" expects no type arguments, but 1 given  [type-arg]
- steam/badge.py:139: error: Variable "steam.types.user.UserT" is not valid as a type  [valid-type]
- steam/badge.py:139: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/badge.py:150: error: "BaseOwnedBadge" expects no type arguments, but 2 given  [type-arg]
- steam/badge.py:150: error: Variable "steam.types.user.UserT" is not valid as a type  [valid-type]
- steam/badge.py:150: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/badge.py:161: error: Variable "steam.types.user.UserT" is not valid as a type  [valid-type]
- steam/badge.py:161: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/badge.py:173: error: "BaseOwnedBadge" expects no type arguments, but 2 given  [type-arg]
- steam/badge.py:173: error: Variable "steam.types.user.UserT" is not valid as a type  [valid-type]
- steam/badge.py:173: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/badge.py:178: error: Variable "steam.types.user.UserT" is not valid as a type  [valid-type]
- steam/badge.py:178: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/badge.py:197: error: "UserBadge" expects no type arguments, but 1 given  [type-arg]
- steam/badge.py:197: error: Variable "steam.types.user.UserT" is not valid as a type  [valid-type]
- steam/badge.py:197: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/badge.py:228: error: Variable "steam.types.user.UserT" is not valid as a type  [valid-type]
- steam/badge.py:228: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/badge.py:238: error: "UserBadge" expects no type arguments, but 1 given  [type-arg]
- steam/badge.py:238: error: Variable "steam.types.user.UserT" is not valid as a type  [valid-type]
- steam/badge.py:238: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/app.py:77: error: Unexpected argument to "TypeVar()": "default"  [misc]
- steam/app.py:81: error: Free type variable expected in Generic[...]  [misc]
- steam/app.py:94: error: Variable "steam.app.NameT" is not valid as a type  [valid-type]
- steam/app.py:94: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/app.py:143: error: "App" expects no type arguments, but 1 given  [type-arg]
+ steam/app.py:438: error: Incompatible default for argument "name" (default has type "None", argument has type "NameT")  [assignment]
+ steam/app.py:438: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
+ steam/app.py:438: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- steam/app.py:424: error: "App" expects no type arguments, but 1 given  [type-arg]
- steam/app.py:424: error: Variable "steam.app.NameT" is not valid as a type  [valid-type]
- steam/app.py:424: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/app.py:438: error: Variable "steam.app.NameT" is not valid as a type  [valid-type]
- steam/app.py:438: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- steam/app.py:515: error: "Leaderboard" expects 1 type argument, but 2 given  [type-arg]
- steam/app.py:541: error: "Leaderboard" expects 1 type argument, but 2 given  [type-arg]
- steam/app.py:567: error: "Leaderboard" expects 1 type argument, but 2 given  [type-arg]
- steam/app.py:881: error: Incompatible types in assignment (expression has type "PublishedFile", variable has type "PublishedFileDetails")  [assignment]
+ steam/app.py:881: error: Incompatible types in assignment (expression has type "PublishedFile[PartialUser]", variable has type "PublishedFileDetails")  [assignment]
- steam/app.py:887: error: UserT? has no attribute "id64"  [attr-defined]
- steam/app.py:983: error: "AppBadge" expects no type arguments, but 1 given  [type-arg]
- steam/app.py:1002: error: "AppBadge" expects no type arguments, but 1 given  [type-arg]
- steam/app.py:1086: error: "PartialApp" expects no type arguments, but 1 given  [type-arg]
- steam/app.py:1159: error: "PartialApp" expects no type arguments, but 1 given  [type-arg]
- steam/app.py:1205: error: "PartialApp" expects no type arguments, but 1 given  [type-arg]
- steam/app.py:1275: error: "PartialApp" expects no type arguments, but 1 given  [type-arg]
- steam/app.py:1386: error: "PartialApp" expects no type arguments, but 1 given  [type-arg]
+ steam/app.py:1435: error: Need type annotation for "partial_dlc"  [var-annotated]

... (truncated 900 lines) ...

discord.py (https://github.com/Rapptz/discord.py)
- discord/_types.py:32: error: Unexpected argument to "TypeVar()": "default"  [misc]
- discord/_types.py:32: error: Unexpected keyword argument "default" for "TypeVar"  [call-arg]
- note: "TypeVar" defined here
- discord/state.py:163: error: Free type variable expected in Generic[...]  [misc]
- discord/state.py:166: error: Variable "discord._types.ClientT" is not valid as a type  [valid-type]
- discord/state.py:166: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- discord/state.py:1617: error: "ConnectionState" expects no type arguments, but 1 given  [type-arg]
- discord/state.py:1617: error: Variable "discord._types.ClientT" is not valid as a type  [valid-type]
- discord/state.py:1617: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- discord/message.py:532: error: Incompatible return value type (got "ConnectionState | Message | None", expected "Message | None")  [return-value]
+ discord/message.py:532: error: Incompatible return value type (got "ConnectionState[Any] | Message | None", expected "Message | None")  [return-value]
- discord/interactions.py:93: error: Free type variable expected in Generic[...]  [misc]
- discord/interactions.py:167: error: "ConnectionState" expects no type arguments, but 1 given  [type-arg]
- discord/interactions.py:167: error: Variable "discord._types.ClientT" is not valid as a type  [valid-type]
- discord/interactions.py:167: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- discord/interactions.py:168: error: "ConnectionState" expects no type arguments, but 1 given  [type-arg]
- discord/interactions.py:168: error: Variable "discord._types.ClientT" is not valid as a type  [valid-type]
- discord/interactions.py:168: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- discord/interactions.py:169: error: Variable "discord._types.ClientT" is not valid as a type  [valid-type]
- discord/interactions.py:169: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- discord/interactions.py:182: error: Incompatible types in assignment (expression has type "object", variable has type "ApplicationCommandInteractionData | MessageComponentInteractionData | ModalSubmitInteractionData | None")  [assignment]
+ discord/interactions.py:182: error: Incompatible types in assignment (expression has type "object", variable has type "ChatInputApplicationCommandInteractionData | UserApplicationCommandInteractionData | MessageApplicationCommandInteractionData | ButtonMessageComponentInteractionData | SelectMessageComponentInteractionData | ModalSubmitInteractionData | None")  [assignment]
- discord/interactions.py:244: error: Variable "discord._types.ClientT" is not valid as a type  [valid-type]
- discord/interactions.py:244: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- discord/interactions.py:255: error: Incompatible return value type (got "ConnectionState | Guild | None", expected "Guild | None")  [return-value]
+ discord/interactions.py:255: error: Incompatible return value type (got "ConnectionState[ClientT] | Guild | None", expected "Guild | None")  [return-value]
- discord/interactions.py:328: error: "InteractionResponse" expects no type arguments, but 1 given  [type-arg]
- discord/interactions.py:328: error: Variable "discord._types.ClientT" is not valid as a type  [valid-type]
- discord/interactions.py:328: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- discord/interactions.py:574: error: Free type variable expected in Generic[...]  [misc]
- discord/interactions.py:587: error: "Interaction" expects no type arguments, but 1 given  [type-arg]
- discord/interactions.py:587: error: Variable "discord._types.ClientT" is not valid as a type  [valid-type]
- discord/interactions.py:587: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- discord/interactions.py:588: error: "Interaction" expects no type arguments, but 1 given  [type-arg]
- discord/interactions.py:588: error: Variable "discord._types.ClientT" is not valid as a type  [valid-type]
- discord/interactions.py:588: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- discord/interactions.py:1071: error: Incompatible types in assignment (expression has type "_InteractionMessageState", base class "Message" defined the type as "ConnectionState")  [assignment]
+ discord/interactions.py:1071: error: Incompatible types in assignment (expression has type "_InteractionMessageState", base class "Message" defined the type as "ConnectionState[Any]")  [assignment]
- discord/client.py:285: error: "ConnectionState" expects no type arguments, but 1 given  [type-arg]
+ discord/client.py:291: error: Incompatible types in assignment (expression has type "Callable[[], Client]", variable has type "Callable[..., Self]")  [assignment]
+ discord/client.py:291: error: Incompatible return value type (got "Client", expected "Self")  [return-value]
- discord/client.py:1164: error: "Interaction" expects no type arguments, but 1 given  [type-arg]
- discord/client.py:1166: error: "Interaction" expects no type arguments, but 1 given  [type-arg]
- discord/client.py:1450: error: "Interaction" expects no type arguments, but 1 given  [type-arg]
- discord/client.py:1452: error: "Interaction" expects no type arguments, but 1 given  [type-arg]
- discord/webhook/sync.py:404: error: Incompatible types in assignment (expression has type "_WebhookState", base class "Message" defined the type as "ConnectionState")  [assignment]
+ discord/webhook/sync.py:404: error: Incompatible types in assignment (expression has type "_WebhookState", base class "Message" defined the type as "ConnectionState[Any]")  [assignment]
- discord/webhook/async_.py:772: error: Incompatible types in assignment (expression has type "_WebhookState", base class "Message" defined the type as "ConnectionState")  [assignment]
+ discord/webhook/async_.py:772: error: Incompatible types in assignment (expression has type "_WebhookState", base class "Message" defined the type as "ConnectionState[Any]")  [assignment]
- discord/webhook/async_.py:1011: error: Incompatible return value type (got "ConnectionState | _WebhookState | Guild | None", expected "Guild | None")  [return-value]
+ discord/webhook/async_.py:1011: error: Incompatible return value type (got "ConnectionState[Any] | _WebhookState | Guild | None", expected "Guild | None")  [return-value]
- discord/ui/view.py:176: error: "Callable[[Any, Interaction, Any], Coroutine[Any, Any, Any]]" has no attribute "__discord_ui_model_type__"  [attr-defined]
+ discord/ui/view.py:176: error: "Callable[[Any, Interaction[Any], Any], Coroutine[Any, Any, Any]]" has no attribute "__discord_ui_model_type__"  [attr-defined]
- discord/ui/view.py:176: error: "Callable[[Any, Interaction, Any], Coroutine[Any, Any, Any]]" has no attribute "__discord_ui_model_kwargs__"  [attr-defined]
+ discord/ui/view.py:176: error: "Callable[[Any, Interaction[Any], Any], Coroutine[Any, Any, Any]]" has no attribute "__discord_ui_model_kwargs__"  [attr-defined]
- discord/ui/item.py:45: error: "Interaction" expects no type arguments, but 1 given  [type-arg]
- discord/ui/item.py:123: error: "Interaction" expects no type arguments, but 1 given  [type-arg]
- discord/ui/item.py:123: error: Variable "discord._types.ClientT" is not valid as a type  [valid-type]
- discord/ui/item.py:123: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- discord/app_commands/tree.py:110: error: Free type variable expected in Generic[...]  [misc]
- discord/app_commands/tree.py:126: error: Variable "discord._types.ClientT" is not valid as a type  [valid-type]
- discord/app_commands/tree.py:126: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- discord/app_commands/tree.py:127: error: Variable "discord._types.ClientT" is not valid as a type  [valid-type]
- discord/app_commands/tree.py:127: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- discord/app_commands/tree.py:128: error: ClientT? has no attribute "http"  [attr-defined]
- discord/app_commands/tree.py:129: error: ClientT? has no attribute "_connection"  [attr-defined]
- discord/app_commands/tree.py:173: error: ClientT? has no attribute "application_id"  [attr-defined]
- discord/app_commands/tree.py:177: error: ClientT? has no attribute "application_id"  [attr-defined]
- discord/app_commands/tree.py:179: error: ClientT? has no attribute "application_id"  [attr-defined]
- discord/app_commands/tree.py:213: error: ClientT? has no attribute "application_id"  [attr-defined]
- discord/app_commands/tree.py:217: error: ClientT? has no attribute "application_id"  [attr-defined]
- discord/app_commands/tree.py:219: error: ClientT? has no attribute "application_id"  [attr-defined]
- discord/app_commands/tree.py:774: error: "Interaction" expects no type arguments, but 1 given  [type-arg]
- discord/app_commands/tree.py:774: error: Variable "discord._types.ClientT" is not valid as a type  [valid-type]
- discord/app_commands/tree.py:774: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- discord/app_commands/tree.py:1054: error: ClientT? has no attribute "application_id"  [attr-defined]
- discord/app_commands/tree.py:1067: error: ClientT? has no attribute "application_id"  [attr-defined]
- discord/app_commands/tree.py:1069: error: ClientT? has no attribute "application_id"  [attr-defined]
- discord/app_commands/tree.py:1077: error: "Interaction" expects no type arguments, but 1 given  [type-arg]

... (truncated 87 lines) ...

@cdce8p
Copy link
Collaborator Author

cdce8p commented Jun 6, 2023

@JelleZijlstra If you've got some time, I'd love to get this in before the next release. It would allow projects to start using default without getting spammed with errors, even if only for better editor completions (e.g. in VS Code). Furthermore, additional real world uses would make the primer results more meaningful.

Depending on time, I could even open a followup which would start using the default value.

@JelleZijlstra
Copy link
Member

Will take a look tonight

tv_arg = self.get_typevarlike_argument(
"TypeVar", param_name, param_value, context, allow_unbound_tvars=True
)
default = tv_arg or AnyType(TypeOfAny.from_error)
elif param_name == "values":
# Probably using obsolete syntax with values=(...). Explain the current syntax.
Copy link
Member

Choose a reason for hiding this comment

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

(Not related to your PR) I wonder when this did work, may have been before typing was in CPython

@JelleZijlstra JelleZijlstra merged commit 2ab8849 into python:master Jun 6, 2023
@cdce8p cdce8p deleted the TypeVar-02-basic-validation branch June 6, 2023 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-pep-696 TypeVar defaults
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants