Add `strict_override_decorator` option (PEP 698)
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅
Diff from mypy_primer, showing the effect of this PR on open source code:
graphql-core (https://github.com/graphql-python/graphql-core): typechecking got 1.06x slower (309.4s -> 327.0s)
(Performance measurements are based on a single noisy sample)
Diff from mypy_primer, showing the effect of this PR on open source code:
steam.py (https://github.com/Gobot1234/steam.py)
- steam/trade.py:336: error: Argument 1 of "__contains__" is incompatible with supertype "Container"; supertype defines the argument type as "object" [override]
- steam/ext/commands/utils.py:24: error: Argument 1 of "__contains__" is incompatible with supertype "Container"; supertype defines the argument type as "object" [override]
- steam/ext/commands/utils.py:36: error: Signature of "get" incompatible with supertype "Mapping" [override]
- steam/ext/commands/utils.py:36: note: Superclass:
- steam/ext/commands/utils.py:36: note: @overload
- steam/ext/commands/utils.py:36: note: def get(self, str, /) -> _VT | None
- steam/ext/commands/utils.py:36: note: @overload
- steam/ext/commands/utils.py:36: note: def [_T] get(self, str, /, default: _VT | _T) -> _VT | _T
- steam/ext/commands/utils.py:36: note: Subclass:
- steam/ext/commands/utils.py:36: note: @overload
- steam/ext/commands/utils.py:36: note: def get(self, k: str) -> _VT | None
- steam/ext/commands/utils.py:36: note: @overload
- steam/ext/commands/utils.py:36: note: def [_T] get(self, k: str, default: _T | None = ...) -> _VT | _T | None
- steam/ext/commands/utils.py:47: note: Subclass:
- steam/ext/commands/utils.py:47: note: @overload
- steam/ext/commands/utils.py:47: note: def pop(self, k: str) -> _VT | None
- steam/ext/commands/utils.py:47: note: @overload
- steam/ext/commands/utils.py:47: note: def [_T] pop(self, k: str, default: _T | None = ...) -> _VT | _T | None
- steam/ext/commands/utils.py:47: error: Signature of "pop" incompatible with supertype "MutableMapping" [override]
- steam/ext/commands/utils.py:47: note: Superclass:
- steam/ext/commands/utils.py:47: note: @overload
- steam/ext/commands/utils.py:47: note: def pop(self, str, /) -> _VT
- steam/ext/commands/utils.py:47: note: @overload
- steam/ext/commands/utils.py:47: note: def [_T] pop(self, str, /, default: _VT | _T) -> _VT | _T
- steam/ext/commands/converters.py:68: error: Argument 2 of "__setitem__" is incompatible with supertype "MutableMapping"; supertype defines the argument type as "tuple[ConverterBase[Any] | BasicConverter[Any], ...]" [override]
werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/datastructures/headers.pyi:108: error: Unused "type: ignore" comment [unused-ignore]
+ src/werkzeug/datastructures/structures.pyi:104: error: Unused "type: ignore" comment [unused-ignore]
+ src/werkzeug/datastructures/structures.pyi:105: error: Unused "type: ignore" comment [unused-ignore]
+ src/werkzeug/datastructures/structures.pyi:149: error: Unused "type: ignore" comment [unused-ignore]
+ src/werkzeug/datastructures/structures.pyi:150: error: Unused "type: ignore" comment [unused-ignore]
+ src/werkzeug/exceptions.py:206: error: Unused "type: ignore" comment [unused-ignore]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/_libs/tslibs/timestamps.pyi:144: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/_libs/tslibs/timestamps.pyi:145: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/_libs/tslibs/timestamps.pyi:146: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/_libs/tslibs/timestamps.pyi:147: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/io/pytables.py:3223: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/io/pytables.py:3298: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/core/internals/array_manager.py:1131: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/plotting/_matplotlib/core.py:1550: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/plotting/_matplotlib/core.py:1789: error: Unused "type: ignore" comment [unused-ignore]
prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/utilities/annotations.py:48: note: Subclass:
- src/prefect/utilities/annotations.py:48: note: def __getitem__(self, Any, /) -> T
- src/prefect/utilities/annotations.py:48: error: Signature of "__getitem__" incompatible with supertype "Sequence" [override]
- src/prefect/utilities/annotations.py:48: note: Superclass:
- src/prefect/utilities/annotations.py:48: note: @overload
- src/prefect/utilities/annotations.py:48: note: def __getitem__(self, int, /) -> <nothing>
- src/prefect/utilities/annotations.py:48: note: @overload
- src/prefect/utilities/annotations.py:48: note: def __getitem__(self, slice, /) -> Sequence[<nothing>]
pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ pandas-stubs/core/series.pyi:2039: error: Unused "type: ignore" comment [unused-ignore]
+ pandas-stubs/core/indexes/interval.pyi:294: error: Unused "type: ignore" comment [unused-ignore]
+ pandas-stubs/core/indexes/interval.pyi:300: error: Unused "type: ignore" comment [unused-ignore]
AutoSplit (https://github.com/Toufool/AutoSplit)
- src/capture_method/__init__.py:87: error: Signature of "get" incompatible with supertype "Mapping" [override]
- src/capture_method/__init__.py:87: note: Superclass:
- src/capture_method/__init__.py:87: note: @overload
- src/capture_method/__init__.py:87: note: def get(self, CaptureMethodEnum, /) -> type[CaptureMethodBase] | None
- src/capture_method/__init__.py:87: note: @overload
- src/capture_method/__init__.py:87: note: def [_T] get(self, CaptureMethodEnum, /, default: type[CaptureMethodBase] | _T) -> type[CaptureMethodBase] | _T
- src/capture_method/__init__.py:87: note: Subclass:
- src/capture_method/__init__.py:87: note: def get(self, CaptureMethodEnum, /) -> Any
Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/context/slash.py:1044: error: Signature of "command" incompatible with supertype "Context" [override]
- tanjun/context/slash.py:1044: note: Superclass:
- tanjun/context/slash.py:1044: note: Optional[ExecutableCommand[SlashContext]]
- tanjun/context/slash.py:1044: note: Subclass:
- tanjun/context/slash.py:1044: note: Optional[BaseSlashCommand]
- tanjun/context/message.py:130: error: Signature of "command" incompatible with supertype "Context" [override]
- tanjun/context/message.py:130: note: Superclass:
- tanjun/context/message.py:130: note: Optional[ExecutableCommand[MessageContext]]
- tanjun/context/message.py:130: note: Subclass:
- tanjun/context/message.py:130: note: Optional[MessageCommand[Any]]
- tanjun/context/menu.py:101: error: Signature of "command" incompatible with supertype "Context" [override]
- tanjun/context/menu.py:101: note: Superclass:
- tanjun/context/menu.py:101: note: Optional[ExecutableCommand[MenuContext]]
- tanjun/context/menu.py:101: note: Subclass:
- tanjun/context/menu.py:101: note: Optional[MenuCommand[Any, Any]]
sublime_debugger (https://github.com/daveleroy/sublime_debugger)
- modules/views/tabbed.py:82: error: Return type "Children" of "render" incompatible with return type "Sequence[element] | element | None" in supertype "element" [override]
- modules/views/breakpoints.py:71: error: Return type "Children" of "render" incompatible with return type "Sequence[element] | element | None" in supertype "element" [override]
- modules/views/debugger.py:39: error: Return type "Children" of "render" incompatible with return type "Sequence[element] | element | None" in supertype "element" [override]
- modules/views/debugger.py:78: error: Return type "Children" of "render" incompatible with return type "Sequence[element] | element | None" in supertype "element" [override]
- modules/views/variables.py:22: error: Return type "Children" of "render" incompatible with return type "Sequence[element] | element | None" in supertype "element" [override]
- modules/views/variables.py:76: error: Return type "Children" of "render" incompatible with return type "Sequence[element] | element | None" in supertype "element" [override]
- modules/views/callstack.py:61: error: Return type "Children" of "render" incompatible with return type "Sequence[element] | element | None" in supertype "element" [override]
- modules/views/callstack.py:96: error: Return type "Children" of "render" incompatible with return type "Sequence[element] | element | None" in supertype "element" [override]
- modules/views/callstack.py:191: error: Return type "Children" of "render" incompatible with return type "Sequence[element] | element | None" in supertype "element" [override]
operator (https://github.com/canonical/operator)
- ops/model.py:668: error: Argument 1 of "__contains__" is incompatible with supertype "Container"; supertype defines the argument type as "object" [override]
- ops/model.py:698: error: Argument 1 of "__contains__" is incompatible with supertype "Container"; supertype defines the argument type as "object" [override]
- ops/model.py:1346: error: Argument 1 of "__contains__" is incompatible with supertype "Container"; supertype defines the argument type as "object" [override]
- ops/model.py:1719: error: Argument 1 of "__contains__" is incompatible with supertype "Container"; supertype defines the argument type as "object" [override]
- ops/framework.py:1250: note: Subclass:
- ops/framework.py:1250: note: def __getitem__(self, int, /) -> Any
- ops/framework.py:1250: error: Signature of "__getitem__" incompatible with supertype "Sequence" [override]
- ops/framework.py:1250: note: Superclass:
- ops/framework.py:1250: note: @overload
- ops/framework.py:1250: note: def __getitem__(self, int, /) -> Any
- ops/framework.py:1250: note: @overload
- ops/framework.py:1250: note: def __getitem__(self, slice, /) -> Sequence[Any]
discord.py (https://github.com/Rapptz/discord.py)
- discord/channel.py:1537: error: Argument 2 of "_update" is incompatible with supertype "GuildChannel"; supertype defines the argument type as "dict[str, Any]" [override]
- discord/webhook/sync.py:406: error: Signature of "edit" incompatible with supertype "PartialMessage" [override]
- discord/webhook/sync.py:406: note: Superclass:
- discord/webhook/sync.py:406: note: @overload
- discord/webhook/sync.py:406: note: def edit(self, *, content: str | None = ..., embed: Embed | None = ..., attachments: Sequence[Attachment | File] = ..., delete_after: float | None = ..., allowed_mentions: AllowedMentions | None = ..., view: View | None = ...) -> Coroutine[Any, Any, Message]
- discord/webhook/sync.py:406: note: @overload
- discord/webhook/sync.py:406: note: def edit(self, *, content: str | None = ..., embeds: Sequence[Embed] = ..., attachments: Sequence[Attachment | File] = ..., delete_after: float | None = ..., allowed_mentions: AllowedMentions | None = ..., view: View | None = ...) -> Coroutine[Any, Any, Message]
- discord/webhook/sync.py:406: note: Subclass:
- discord/webhook/sync.py:406: note: def edit(self, *, content: str | None = ..., embeds: Sequence[Embed] = ..., embed: Embed | None = ..., attachments: Sequence[Attachment | File] = ..., allowed_mentions: AllowedMentions | None = ...) -> SyncWebhookMessage
- discord/webhook/async_.py:774: note: Subclass:
- discord/webhook/async_.py:774: note: def edit(self, *, content: str | None = ..., embeds: Sequence[Embed] = ..., embed: Embed | None = ..., attachments: Sequence[Attachment | File] = ..., view: View | None = ..., allowed_mentions: AllowedMentions | None = ...) -> Coroutine[Any, Any, WebhookMessage]
- discord/webhook/async_.py:774: error: Signature of "edit" incompatible with supertype "PartialMessage" [override]
- discord/webhook/async_.py:774: note: Superclass:
- discord/webhook/async_.py:774: note: @overload
- discord/webhook/async_.py:774: note: def edit(self, *, content: str | None = ..., embed: Embed | None = ..., attachments: Sequence[Attachment | File] = ..., delete_after: float | None = ..., allowed_mentions: AllowedMentions | None = ..., view: View | None = ...) -> Coroutine[Any, Any, Message]
- discord/webhook/async_.py:774: note: @overload
- discord/webhook/async_.py:774: note: def edit(self, *, content: str | None = ..., embeds: Sequence[Embed] = ..., attachments: Sequence[Attachment | File] = ..., delete_after: float | None = ..., allowed_mentions: AllowedMentions | None = ..., view: View | None = ...) -> Coroutine[Any, Any, Message]
urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/poolmanager.py:618: error: Unused "type: ignore" comment [unused-ignore]
ibis (https://github.com/ibis-project/ibis)
- ibis/expr/datatypes/core.py:400: error: Argument 1 of "__contains__" is incompatible with supertype "Sequence"; supertype defines the argument type as "object" [override]
- ibis/expr/datatypes/core.py:400: error: Argument 1 of "__contains__" is incompatible with supertype "Container"; supertype defines the argument type as "object" [override]
- ibis/backends/dask/__init__.py:96: error: Signature of "compile" incompatible with supertype "BaseBackend" [override]
- ibis/backends/dask/__init__.py:96: note: Superclass:
- ibis/backends/dask/__init__.py:96: note: def compile(self, expr: Expr, params: Mapping[Expr, Any] | None = ...) -> Any
- ibis/backends/dask/__init__.py:96: note: Subclass:
- ibis/backends/dask/__init__.py:96: note: def compile(self, query: Expr, params: Mapping[Expr, object] | None = ..., **kwargs: Any) -> Any
- ibis/backends/dask/__init__.py:113: error: Argument 2 of "table" is incompatible with supertype "BaseBackend"; supertype defines the argument type as "str | None" [override]
- ibis/backends/dask/__init__.py:113: note: This violates the Liskov substitution principle
- ibis/backends/dask/__init__.py:113: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- ibis/backends/pyspark/__init__.py:571: note: Superclass:
- ibis/backends/pyspark/__init__.py:571: note: @classmethod
- ibis/backends/pyspark/__init__.py:571: note: def has_operation(cls, operation: type[Value]) -> bool
- ibis/backends/pyspark/__init__.py:571: note: Subclass:
- ibis/backends/pyspark/__init__.py:571: note: def has_operation(cls, operation: type[Value]) -> bool
- ibis/backends/pyspark/__init__.py:571: error: Signature of "has_operation" incompatible with supertype "BaseBackend" [override]
- ibis/backends/trino/__init__.py:28: error: Signature of "current_database" incompatible with supertype "BaseBackend" [override]
- ibis/backends/trino/__init__.py:28: note: Superclass:
- ibis/backends/trino/__init__.py:28: note: str | None
- ibis/backends/trino/__init__.py:28: note: Subclass:
- ibis/backends/trino/__init__.py:28: note: def current_database(self) -> str
- ibis/backends/duckdb/__init__.py:78: note: Subclass:
- ibis/backends/duckdb/__init__.py:78: note: def current_database(self) -> str
- ibis/backends/duckdb/__init__.py:78: error: Signature of "current_database" incompatible with supertype "BaseBackend" [override]
- ibis/backends/duckdb/__init__.py:78: note: Superclass:
- ibis/backends/duckdb/__init__.py:78: note: str | None
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅
Pushed a new update. The error message now includes the base class name. Similar to pyright.
The PR would be ready now.
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅
Diff from mypy_primer, showing the effect of this PR on open source code:
vision (https://github.com/pytorch/vision): typechecking got 1.32x slower (32.2s -> 42.6s)
(Performance measurements are based on a single noisy sample)
Thanks for the review @JukkaL! Using a new error code instead of a cmd line option does make sense. The change was fairly strait forward. With that I also updated the documentation and added a whole new section in error_code_list2.rst.
For now I used explicit-override as error code. Happy to change that if we can come up with something better though.
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅