Skip to content

More typeddict fixes - #5756

Open
yangdanny97 wants to merge 3 commits into
pyrefly-org:mainfrom
yangdanny97:typeddict-2
Open

yangdanny97 wants to merge 3 commits into
pyrefly-org:mainfrom
yangdanny97:typeddict-2

Conversation

@yangdanny97

@yangdanny97 yangdanny97 commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds 2 more test cases for David Halter's comments on python/typing#2338 (comment)

In the following excerpt below (see linked comment for context)

if bool():
    a1 = a2  # (1) This should error
else:
    a2 = a1  # (2)

Pyrefly currently does not error on 1; this PR also fixes that behavior

The PR only adds one rule: the target's extra-kwarg type must also be assignable to every source keyword parameter the target doesn't name.

The actual delta is larger because Claude found a simpler representation of the rules that uses fewer match cases

  • I am a human, and I fully understand the code I am submitting.

Test Plan

test.py

primer - the new errors should be correct per the implemented rules, the fix would be to mark the relevant TypedDicts as closed

@github-actions

Copy link
Copy Markdown

✅ This PR meets all requirements from our pull request checklist.

Optional recommendations:

  • If this PR addresses an open issue, please link the issue in the PR description and claim it.

Note: this comment updates automatically after changes to the PR. Updates may take up to half an hour.

@meta-codesync

meta-codesync Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D134402139. (Because this pull request was imported automatically, there will not be any future comments.)

@github-actions github-actions Bot added size/s and removed size/s labels Nov 25, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added size/s and removed size/s labels Nov 25, 2026
@yangdanny97
yangdanny97 marked this pull request as ready for review November 25, 2026 03:57
@github-actions

Copy link
Copy Markdown

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

============================================================
SUMMARY
============================================================
Total: +11 new errors, -0 fixed errors
By preset: +11/-0 (default), +11/-0 (strict)

Projects with changes (4):
  discord.py: +2 -0
  strawberry: +4 -0
  steam.py: +4 -0
  aiohttp: +1 -0
============================================================

FULL DIFF DETAILS
------------------------------------------------------------

discord.py (https://github.com/Rapptz/discord.py)
+ ERROR discord/ext/commands/core.py:1775:5-12: Implementation signature `(name: str = ..., cls: type[Command[Any, ..., Any]] = ..., **attrs: Unpack[_CommandDecoratorKwargs]) -> Any` does not accept all arguments that overload signature `(name: str = ..., **attrs: Unpack[_CommandDecoratorKwargs]) -> _CommandDecorator` accepts [inconsistent-overload]
+ ERROR discord/ext/commands/core.py:1835:5-10: Implementation signature `(name: str = ..., cls: type[Group[Any, ..., Any]] = ..., **attrs: Unpack[_GroupDecoratorKwargs]) -> Any` does not accept all arguments that overload signature `(name: str = ..., **attrs: Unpack[_GroupDecoratorKwargs]) -> _GroupDecorator` accepts [inconsistent-overload]

strawberry (https://github.com/strawberry-graphql/strawberry)
+ ERROR strawberry/federation/field.py:75:5-10: Implementation signature `(resolver: ((...) -> Awaitable[Any]) | ((...) -> Coroutine[Any, Any, Any]) | ((...) -> Any) | StrawberryResolver[Any] | classmethod[Any, ..., Any] | staticmethod[..., Any] | None = None, *, name: str | None = None, is_subscription: bool = False, description: str | None = None, permission_classes: list[type[BasePermission]] | None = None, deprecation_reason: str | None = None, default: Any = _MISSING_TYPE.MISSING, default_factory: ((...) -> object) | object = _MISSING_TYPE.MISSING, metadata: Mapping[Any, Any] | None = None, directives: Sequence[object] | None = ..., extensions: list[FieldExtension] | None = None, graphql_type: Any | None = None, init: bool | None = None, **federation_kwargs: Unpack[FederationFieldParams]) -> Any` does not accept all arguments that overload signature `(*, name: str | None = None, is_subscription: bool = False, description: str | None = None, init: Literal[True] = True, permission_classes: list[type[BasePermission]] | None = None, deprecation_reason: str | None = None, default: Any = _MISSING_TYPE.MISSING, default_factory: ((...) -> object) | object = _MISSING_TYPE.MISSING, metadata: Mapping[Any, Any] | None = None, directives: Sequence[object] | None = ..., extensions: list[FieldExtension] | None = None, graphql_type: Any | None = None, **federation_kwargs: Unpack[FederationFieldParams]) -> Any` accepts [inconsistent-overload]
+ ERROR strawberry/federation/object_type.py:81:5-9: Implementation signature `(cls: T | None = None, *, name: str | None = None, description: str | None = None, directives: Iterable[object] = ..., **federation_kwargs: Unpack[FederationTypeParams]) -> Unknown` does not accept all arguments that overload signature `(*, name: str | None = None, description: str | None = None, directives: Iterable[object] = ..., **federation_kwargs: Unpack[FederationTypeParams]) -> [T: type[Any]](T) -> T` accepts [inconsistent-overload]
+ ERROR strawberry/federation/object_type.py:186:5-14: Implementation signature `(cls: T | None = None, *, name: str | None = None, description: str | None = None, directives: Iterable[object] = ..., **federation_kwargs: Unpack[FederationInterfaceParams]) -> Unknown` does not accept all arguments that overload signature `(*, name: str | None = None, description: str | None = None, directives: Iterable[object] = ..., **federation_kwargs: Unpack[FederationInterfaceParams]) -> [T: type[Any]](T) -> T` accepts [inconsistent-overload]
+ ERROR strawberry/federation/object_type.py:235:5-21: Implementation signature `(cls: T | None = None, *, name: str | None = None, description: str | None = None, directives: Iterable[object] = ..., **federation_kwargs: Unpack[FederationInterfaceParams]) -> Unknown` does not accept all arguments that overload signature `(*, name: str | None = None, description: str | None = None, directives: Iterable[object] = ..., **federation_kwargs: Unpack[FederationInterfaceParams]) -> [T: type[Any]](T) -> T` accepts [inconsistent-overload]

steam.py (https://github.com/Gobot1234/steam.py)
+ ERROR steam/ext/commands/commands.py:695:9-16: Implementation signature `(self: Self@GroupMixin, callback: CoroFuncT | None = None, /, *, name: str | None = None, cls: type[C] = ..., **attrs: Any) -> ((CoroFuncT) -> C) | C` does not accept all arguments that overload signature `(self: Self@GroupMixin, **kwargs: Unpack[CommandKwargsNoCls]) -> [**P = ..., R = Any](CallbackT) -> Command[CogT, P, R]` accepts [inconsistent-overload]
+ ERROR steam/ext/commands/commands.py:741:9-14: Implementation signature `(self: Self@GroupMixin, callback: CoroFuncT | None = None, /, *, name: str | None = None, cls: type[G] | None = None, **attrs: Any) -> ((CoroFuncT) -> G) | G` does not accept all arguments that overload signature `(self: Self@GroupMixin, **kwargs: Unpack[CommandKwargsNoCls]) -> [**P = ..., R = Any](CallbackT) -> Group[CogT, P, R]` accepts [inconsistent-overload]
+ ERROR steam/ext/commands/commands.py:795:5-12: Implementation signature `(callback: CoroFuncT | None = None, /, *, name: str | None = None, cls: type[C] = ..., **attrs: Any) -> ((CoroFuncT) -> C) | C` does not accept all arguments that overload signature `(**kwargs: Unpack[CommandKwargsNoCls]) -> [CogT: Bot | Cog | None = Bot | Cog | None, **P = ..., R = Any](CallbackT) -> Command[CogT, P, R]` accepts [inconsistent-overload]
+ ERROR steam/ext/commands/commands.py:844:5-10: Implementation signature `(callback: CoroFuncT | None = None, /, *, name: str | None = None, cls: type[G] | None = None, **attrs: Any) -> ((CoroFuncT) -> G) | G` does not accept all arguments that overload signature `(**kwargs: Unpack[CommandKwargsNoCls]) -> [CogT: Bot | Cog | None = Bot | Cog | None, **P = ..., R = Any](CallbackT) -> Group[CogT, P, R]` accepts [inconsistent-overload]

aiohttp (https://github.com/aio-libs/aiohttp)
+ ERROR aiohttp/web_server.py:50:9-17: Implementation signature `(self: Self@Server, handler: (_Request) -> Awaitable[StreamResponse], *, request_factory: ((RawRequestMessage | Unknown, StreamReader, RequestHandler[_Request], AbstractStreamWriter, Task[None], HTTPBadRequest | None) -> _Request) | None = None, debug: bool | None = None, handler_cancellation: bool = False, **kwargs: Unpack[_RequestHandlerKwargs]) -> None` does not accept all arguments that overload signature `(self: Server[BaseRequest], handler: (_Request) -> Awaitable[StreamResponse], *, debug: bool | None = None, handler_cancellation: bool = False, **kwargs: Unpack[_RequestHandlerKwargs]) -> None` accepts [inconsistent-overload]

@stroxler stroxler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants