-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
gh-20418: Fix false positive override error for overloaded methods with narrower return types #20525
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
Draft
a12k
wants to merge
3
commits into
python:master
Choose a base branch
from
a12k:fix-overload-lsp-return-coverage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+41
−0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This comment has been minimized.
This comment has been minimized.
Contributor
Author
|
Based on the above it looks like my change is a little too permissive. Will work on this 🙃 |
… pass mypy_primer
This comment has been minimized.
This comment has been minimized.
… pass mypy_primer
Contributor
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!