-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Apply TypeVar defaults to functions (PEP 696) #15387
Conversation
@hauntsaninja Any idea why the primer comment job is failing? The primer run with artifact looks fine This seems to have started last night. Strangely enough, everything continues to work fine on my fork with the same config. -- |
20f2c17
to
85eb940
Compare
This comment has been minimized.
This comment has been minimized.
@JelleZijlstra This is the next one for PEP 696. Fairly small. The primer result is as expected. |
I think we actually don't want defaults to be used for functions? https://peps.python.org/pep-0696/#function-defaults cc @Gobot1234 |
I actually used the pyright test case here to implement it. Basically the default is ignored unless mypy would return
Mypy detects this as well
|
85eb940
to
c58532e
Compare
Moved the validation portion to a separate PR #15442 as that likely uncontroversial. Although I still think, this PR is the correct move as it matches mypy prior behavior and the way pyright handles it. The |
This comment has been minimized.
This comment has been minimized.
c58532e
to
3d42c57
Compare
This comment has been minimized.
This comment has been minimized.
3d42c57
to
1874722
Compare
Diff from mypy_primer, showing the effect of this PR on open source code: steam.py (https://github.com/Gobot1234/steam.py)
- steam/id.py:576: error: Need type annotation for "id" [var-annotated]
- 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/app.py:1435: error: Need type annotation for "partial_dlc" [var-annotated]
- steam/app.py:1447: error: List comprehension has incompatible type List[PartialPackage[<nothing>]]; expected List[FetchedAppPackage] [misc]
+ steam/app.py:1447: error: List comprehension has incompatible type List[PartialPackage[str | None]]; expected List[FetchedAppPackage] [misc]
- steam/package.py:357: error: Need type annotation for "master_package" [var-annotated]
- steam/game_server.py:319: error: Need type annotation for "app" [var-annotated]
- steam/profile.py:119: error: Need type annotation for "app" [var-annotated]
- steam/profile.py:144: error: Need type annotation for "msg" [var-annotated]
- steam/manifest.py:552: error: Need type annotation for "app" [var-annotated]
- steam/manifest.py:967: error: Need type annotation for "parent" [var-annotated]
- steam/manifest.py:1126: error: Need type annotation for "_apps" [var-annotated]
+ steam/manifest.py:1158: error: Incompatible return value type (got "list[PartialApp[str | None]]", expected "list[PartialApp[None]] | list[PartialApp[str]]") [return-value]
- steam/user.py:266: error: Need type annotation for "new_message" [var-annotated]
- steam/published_file.py:210: error: Need type annotation for "created_with" [var-annotated]
- steam/event.py:77: error: Need type annotation for "app" [var-annotated]
- steam/event.py:276: error: Incompatible types in assignment (expression has type "App[Any] | None", variable has type "PartialApp[Any] | None") [assignment]
+ steam/event.py:276: error: Incompatible types in assignment (expression has type "App[Any] | PartialApp[str | None] | None", variable has type "PartialApp[str | None] | None") [assignment]
- steam/clan.py:542: error: Need type annotation for "event" [var-annotated]
- steam/state.py:304: error: Need type annotation for "steam_id" [var-annotated]
- steam/state.py:304: error: Argument "type" to "ID" has incompatible type "int"; expected "None" [arg-type]
+ steam/state.py:304: error: Argument "type" to "ID" has incompatible type "int"; expected "Type | None" [arg-type]
- steam/state.py:617: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:677: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:700: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:721: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:731: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:739: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:777: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:788: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:801: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:1388: error: Need type annotation for "id" [var-annotated]
- steam/state.py:1430: error: Incompatible types in assignment (expression has type "ID[Any]", variable has type "Clan") [assignment]
+ steam/state.py:1430: error: Incompatible types in assignment (expression has type "Clan | ID[Type]", variable has type "Clan") [assignment]
- steam/state.py:1432: error: Incompatible types in assignment (expression has type "ID[Any]", variable has type "Clan") [assignment]
+ steam/state.py:1432: error: Incompatible types in assignment (expression has type "ID[Type]", variable has type "Clan") [assignment]
- steam/state.py:1720: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:1813: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:1852: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:1872: error: Need type annotation for "steam_id" [var-annotated]
- steam/state.py:1915: error: Need type annotation for "license_" [var-annotated]
- steam/state.py:2352: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:2359: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:2377: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:2388: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:2398: error: Need type annotation for "msg" [var-annotated]
- steam/state.py:2418: error: Need type annotation for "msg" [var-annotated]
- steam/bundle.py:98: error: Need type annotation for "_apps" [var-annotated]
- steam/bundle.py:99: error: Need type annotation for "_packages" [var-annotated]
- steam/store.py:75: error: Need type annotation for "package" [var-annotated]
- steam/store.py:76: error: Need type annotation for "bundle" [var-annotated]
- steam/store.py:171: error: Need type annotation for "_apps" [var-annotated]
- steam/store.py:186: error: Need type annotation for "related_parent_app" [var-annotated]
- steam/store.py:327: error: Need type annotation for "package" [var-annotated]
- steam/client.py:572: error: Need type annotation for "steam_id" [var-annotated]
- steam/client.py:572: error: Argument "type" to "ID" has incompatible type "int"; expected "None" [arg-type]
+ steam/client.py:572: error: Argument "type" to "ID" has incompatible type "int"; expected "Type | None" [arg-type]
- steam/client.py:646: error: Need type annotation for "steam_id" [var-annotated]
- steam/client.py:646: error: Argument "type" to "ID" has incompatible type "int"; expected "None" [arg-type]
+ steam/client.py:646: error: Argument "type" to "ID" has incompatible type "int"; expected "Type | None" [arg-type]
- steam/client.py:658: error: Need type annotation for "steam_id" [var-annotated]
- steam/client.py:658: error: Argument "type" to "ID" has incompatible type "int"; expected "None" [arg-type]
+ steam/client.py:658: error: Argument "type" to "ID" has incompatible type "int"; expected "Type | None" [arg-type]
- steam/client.py:1154: error: Need type annotation for "trades" [var-annotated]
|
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.
Thanks for working on this!
Use TypeVar defaults to resolve fallback return type of functions.
Note: Defaults for TypeVarTuples don't yet work, probably a result of the limited support for
Unpack
/TypeVarTuple
.Ref: #14851