Skip to content

Conversation

@a12k
Copy link
Contributor

@a12k a12k commented Jan 5, 2026

Fixes gh-20418

This one fixes an issue with overloaded methods in subclasses being marked incompatible in the supertype, even if the overloads collectively covered the base class signature. Basically, it verifies that all return types in an overloaded set are subtypes of the original set, and checks the implementation type against the original signature to confirm argument coverage.

Added a regression test (which is basically the repro from the original issue, I am claiming no points for originality) and it is fixed in the orignal repro from gh-20418!

@github-actions

This comment has been minimized.

@a12k a12k marked this pull request as draft January 5, 2026 17:13
@a12k
Copy link
Contributor Author

a12k commented Jan 5, 2026

Based on the above it looks like my change is a little too permissive. Will work on this 🙃

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

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

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/task_runners.py:413: error: Signature of "map" incompatible with supertype "TaskRunner"  [override]
- src/prefect/task_runners.py:413: note:      Superclass:
- src/prefect/task_runners.py:413: note:          def [P`6177, R] map(self, task: Task[P, R | CoroutineType[Any, Any, R]], parameters: dict[str, Any | unmapped | allow_failure], wait_for: Iterable[PrefectFuture[R]] | None = ...) -> PrefectFutureList[PrefectConcurrentFuture[R]]
- src/prefect/task_runners.py:413: note:      Subclass:
- src/prefect/task_runners.py:413: note:          @overload
- src/prefect/task_runners.py:413: note:          def [P`6176] map(self, task: Task[P, CoroutineType[Any, Any, R]], parameters: dict[str, Any], wait_for: Iterable[PrefectFuture[Any]] | None = ...) -> PrefectFutureList[PrefectConcurrentFuture[R]]
- src/prefect/task_runners.py:413: note:          @overload
- src/prefect/task_runners.py:413: note:          def map(self, task: Task[Any, R], parameters: dict[str, Any], wait_for: Iterable[PrefectFuture[Any]] | None = ...) -> PrefectFutureList[PrefectConcurrentFuture[R]]
- src/prefect/task_runners.py:954: error: Signature of "map" incompatible with supertype "TaskRunner"  [override]
- src/prefect/task_runners.py:954: note:      Superclass:
- src/prefect/task_runners.py:954: note:          def [P`6246, R] map(self, task: Task[P, R | CoroutineType[Any, Any, R]], parameters: dict[str, Any | unmapped | allow_failure], wait_for: Iterable[PrefectFuture[R]] | None = ...) -> PrefectFutureList[PrefectDistributedFuture[R]]
- src/prefect/task_runners.py:954: note:      Subclass:
- src/prefect/task_runners.py:954: note:          @overload
- src/prefect/task_runners.py:954: note:          def [P`6245] map(self, task: Task[P, CoroutineType[Any, Any, R]], parameters: dict[str, Any], wait_for: Iterable[PrefectFuture[Any]] | None = ...) -> PrefectFutureList[PrefectDistributedFuture[R]]
- src/prefect/task_runners.py:954: note:          @overload
- src/prefect/task_runners.py:954: note:          def map(self, task: Task[Any, R], parameters: dict[str, Any], wait_for: Iterable[PrefectFuture[Any]] | None = ...) -> PrefectFutureList[PrefectDistributedFuture[R]]

aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/helpers.py:914: error: Unused "type: ignore" comment  [unused-ignore]
+ aiohttp/web_response.py:492: error: Unused "type: ignore" comment  [unused-ignore]
+ aiohttp/web_response.py:501: error: Unused "type: ignore" comment  [unused-ignore]
+ aiohttp/web_request.py:261: error: Unused "type: ignore" comment  [unused-ignore]
+ aiohttp/web_request.py:270: error: Unused "type: ignore" comment  [unused-ignore]
+ aiohttp/web_app.py:142: error: Unused "type: ignore" comment  [unused-ignore]
+ aiohttp/web_app.py:157: error: Unused "type: ignore" comment  [unused-ignore]

core (https://github.com/home-assistant/core)
+ homeassistant/util/hass_dict.pyi:32: error: Unused "type: ignore" comment  [unused-ignore]
+ homeassistant/util/hass_dict.pyi:40: error: Unused "type: ignore" comment  [unused-ignore]

steam.py (https://github.com/Gobot1234/steam.py)
- steam/ext/csgo/models.py:179: error: Signature of "inventory" incompatible with supertype "steam._gc.client.ClientUser"  [override]
- steam/ext/csgo/models.py:179: note:      Superclass:
- steam/ext/csgo/models.py:179: note:          def inventory(self, app: App[str | None], *, context_id: int | None = ..., language: Language | None = ...) -> Coroutine[Any, Any, Inventory[Item[ClientUser], ClientUser]]
- steam/ext/csgo/models.py:179: note:      Subclass:
- steam/ext/csgo/models.py:179: note:          @overload
- steam/ext/csgo/models.py:179: note:          def inventory(self, app: Any, *, language: object = ...) -> Coroutine[Any, Any, Backpack]
- steam/ext/csgo/models.py:179: note:          @overload
- steam/ext/csgo/models.py:179: note:          def inventory(self, app: App[str | None], *, language: Language | None = ...) -> Coroutine[Any, Any, Inventory[Item[ClientUser], ClientUser]]
- steam/ext/csgo/models.py:179: error: Signature of "inventory" incompatible with supertype "steam.user.ClientUser"  [override]
- steam/ext/csgo/models.py:179: note:      Superclass:
- steam/ext/csgo/models.py:179: note:          def inventory(self, App[str | None], /, *, context_id: int | None = ..., language: Language | None = ...) -> Coroutine[Any, Any, Inventory[Item[ClientUser], ClientUser]]
- steam/ext/csgo/models.py:179: note:      Subclass:
- steam/ext/csgo/models.py:179: note:          @overload
- steam/ext/csgo/models.py:179: note:          def inventory(self, app: Any, *, language: object = ...) -> Coroutine[Any, Any, Backpack]
- steam/ext/csgo/models.py:179: note:          @overload
- steam/ext/csgo/models.py:179: note:          def inventory(self, app: App[str | None], *, language: Language | None = ...) -> Coroutine[Any, Any, Inventory[Item[ClientUser], ClientUser]]
- steam/ext/csgo/models.py:179: error: Signature of "inventory" incompatible with supertype "steam.abc.PartialUser"  [override]
- steam/ext/csgo/models.py:179: note:      Superclass:
- steam/ext/csgo/models.py:179: note:          def inventory(self, App[str | None], /, *, context_id: int | None = ..., language: Language | None = ...) -> Coroutine[Any, Any, Inventory[Item[ClientUser], ClientUser]]
- steam/ext/csgo/models.py:179: note:      Subclass:
- steam/ext/csgo/models.py:179: note:          @overload
- steam/ext/csgo/models.py:179: note:          def inventory(self, app: Any, *, language: object = ...) -> Coroutine[Any, Any, Backpack]
- steam/ext/csgo/models.py:179: note:          @overload
- steam/ext/csgo/models.py:179: note:          def inventory(self, app: App[str | None], *, language: Language | None = ...) -> Coroutine[Any, Any, Inventory[Item[ClientUser], ClientUser]]
- steam/ext/tf2/client.py:36: error: Signature of "inventory" incompatible with supertype "steam._gc.client.ClientUser"  [override]
- steam/ext/tf2/client.py:36: note:      Superclass:
- steam/ext/tf2/client.py:36: note:          def inventory(self, app: App[str | None], *, context_id: int | None = ..., language: Language | None = ...) -> Coroutine[Any, Any, Inventory[Item[ClientUser], ClientUser]]
- steam/ext/tf2/client.py:36: note:      Subclass:
- steam/ext/tf2/client.py:36: note:          @overload
- steam/ext/tf2/client.py:36: note:          def inventory(self, app: Any, *, language: object = ...) -> Coroutine[Any, Any, Backpack]
- steam/ext/tf2/client.py:36: note:          @overload
- steam/ext/tf2/client.py:36: note:          def inventory(self, app: App[str | None], *, language: Language | None = ...) -> Coroutine[Any, Any, Inventory[Item[ClientUser], ClientUser]]
- steam/ext/tf2/client.py:36: error: Signature of "inventory" incompatible with supertype "steam.user.ClientUser"  [override]
- steam/ext/tf2/client.py:36: note:      Superclass:
- steam/ext/tf2/client.py:36: note:          def inventory(self, App[str | None], /, *, context_id: int | None = ..., language: Language | None = ...) -> Coroutine[Any, Any, Inventory[Item[ClientUser], ClientUser]]
- steam/ext/tf2/client.py:36: note:      Subclass:
- steam/ext/tf2/client.py:36: note:          @overload
- steam/ext/tf2/client.py:36: note:          def inventory(self, app: Any, *, language: object = ...) -> Coroutine[Any, Any, Backpack]
- steam/ext/tf2/client.py:36: note:          @overload
- steam/ext/tf2/client.py:36: note:          def inventory(self, app: App[str | None], *, language: Language | None = ...) -> Coroutine[Any, Any, Inventory[Item[ClientUser], ClientUser]]
- steam/ext/tf2/client.py:36: error: Signature of "inventory" incompatible with supertype "steam.abc.PartialUser"  [override]
- steam/ext/tf2/client.py:36: note:      Superclass:
- steam/ext/tf2/client.py:36: note:          def inventory(self, App[str | None], /, *, context_id: int | None = ..., language: Language | None = ...) -> Coroutine[Any, Any, Inventory[Item[ClientUser], ClientUser]]
- steam/ext/tf2/client.py:36: note:      Subclass:
- steam/ext/tf2/client.py:36: note:          @overload
- steam/ext/tf2/client.py:36: note:          def inventory(self, app: Any, *, language: object = ...) -> Coroutine[Any, Any, Backpack]
- steam/ext/tf2/client.py:36: note:          @overload
- steam/ext/tf2/client.py:36: note:          def inventory(self, app: App[str | None], *, language: Language | None = ...) -> Coroutine[Any, Any, Inventory[Item[ClientUser], ClientUser]]

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/frame.py:12938: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/core/frame.py:13031: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/core/frame.py:13078: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/core/frame.py:13313: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/core/frame.py:13360: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/core/frame.py:13409: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/core/frame.py:13529: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/core/frame.py:13648: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/core/frame.py:13774: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/core/frame.py:13894: error: Unused "type: ignore" comment  [unused-ignore]

discord.py (https://github.com/Rapptz/discord.py)
- discord/interactions.py:1429: error: Signature of "edit" incompatible with supertype "discord.message.Message"  [override]
- discord/interactions.py:1429: note:      Superclass:
- discord/interactions.py:1429: note:          def edit(self, *, content: str | None = ..., embed: Embed | None = ..., embeds: Sequence[Embed] = ..., attachments: Sequence[Attachment | File] = ..., suppress: bool = ..., delete_after: float | None = ..., allowed_mentions: AllowedMentions | None = ..., view: View | LayoutView | None = ...) -> Coroutine[Any, Any, Message]
- discord/interactions.py:1429: note:      Subclass:
- discord/interactions.py:1429: note:          @overload
- discord/interactions.py:1429: note:          def edit(self, *, attachments: Sequence[Attachment | File] = ..., view: LayoutView, allowed_mentions: AllowedMentions | None = ..., delete_after: float | None = ...) -> Coroutine[Any, Any, InteractionMessage]
- discord/interactions.py:1429: note:          @overload
- discord/interactions.py:1429: note:          def edit(self, *, content: str | None = ..., embeds: Sequence[Embed] = ..., embed: Embed | None = ..., attachments: Sequence[Attachment | File] = ..., view: View | None = ..., allowed_mentions: AllowedMentions | None = ..., delete_after: float | None = ..., poll: Poll = ...) -> Coroutine[Any, Any, InteractionMessage]
- discord/interactions.py:1429: error: Signature of "edit" incompatible with supertype "discord.message.PartialMessage"  [override]
- discord/interactions.py:1429: note:      Superclass:
- discord/interactions.py:1429: note:          def edit(self, *, content: str | None = ..., embed: Embed | None = ..., embeds: Sequence[Embed] = ..., attachments: Sequence[Attachment | File] = ..., delete_after: float | None = ..., allowed_mentions: AllowedMentions | None = ..., view: View | LayoutView | None = ...) -> Coroutine[Any, Any, Message]
- discord/interactions.py:1429: note:      Subclass:
- discord/interactions.py:1429: note:          @overload
- discord/interactions.py:1429: note:          def edit(self, *, attachments: Sequence[Attachment | File] = ..., view: LayoutView, allowed_mentions: AllowedMentions | None = ..., delete_after: float | None = ...) -> Coroutine[Any, Any, InteractionMessage]
- discord/interactions.py:1429: note:          @overload
- discord/interactions.py:1429: note:          def edit(self, *, content: str | None = ..., embeds: Sequence[Embed] = ..., embed: Embed | None = ..., attachments: Sequence[Attachment | File] = ..., view: View | None = ..., allowed_mentions: AllowedMentions | None = ..., delete_after: float | None = ..., poll: Poll = ...) -> Coroutine[Any, Any, InteractionMessage]

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ pandas-stubs/core/indexes/multi.pyi:195: error: Unused "type: ignore" comment  [unused-ignore]

pywin32 (https://github.com/mhammond/pywin32)
+ win32/Lib/win32timezone.py:671: error: Unused "type: ignore" comment  [unused-ignore]
+ win32/Lib/win32timezone.py:726: error: Unused "type: ignore" comment  [unused-ignore]
+ win32/Lib/win32timezone.py:737: error: Unused "type: ignore" comment  [unused-ignore]

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.

Errors on @overload in supertype signatures

1 participant