PEP 702 (@deprecated): overriding deprecated methods#18085
Open
tyralla wants to merge 2 commits into
Open
Conversation
…ges in a prototype manner for first discussions.
for more information, see https://pre-commit.ci
Collaborator
Author
|
@JelleZijlstra: I am not allowed to add the correct label, am I? |
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: Tanjun (https://github.com/FasterSpeeding/Tanjun)
+ tanjun/context/slash.py:1045: note: Superclass:
+ tanjun/context/slash.py:1045: note: Optional[ExecutableCommand[SlashContext]]
+ tanjun/context/slash.py:1045: note: Subclass:
+ tanjun/context/slash.py:1045: note: Optional[BaseSlashCommand]
+ 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: 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]]
steam.py (https://github.com/Gobot1234/steam.py)
+ steam/ext/csgo/models.py:178: note: Superclass:
+ steam/ext/csgo/models.py:178: 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:178: note: Subclass:
+ steam/ext/csgo/models.py:178: note: @overload
+ steam/ext/csgo/models.py:178: note: def inventory(self, app: Any, *, language: object = ...) -> Coroutine[Any, Any, Backpack]
+ steam/ext/csgo/models.py:178: note: @overload
+ steam/ext/csgo/models.py:178: note: def inventory(self, app: App[str | None], *, language: Language | None = ...) -> Coroutine[Any, Any, Inventory[Item[ClientUser], ClientUser]]
|
JelleZijlstra
left a comment
Member
There was a problem hiding this comment.
Sorry I dropped the ball on this. This now has a merge conflict.
My thoughts on your questions:
- I don't think we should emit an error in the case where B incompatibly overrides A, and C compatibly overrides B. That feels like noise. However, that's an independent change from this one.
- Regarding overloads, I think it's fine to not worry about overrides that override one deprecated overload from an overload set.
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
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.
I think some points need discussion before implementing everything neatly, especially regarding overloads. So, my first (untidy) commit focuses on "normal" methods (
testDeprecatedOverriddenMethod).Is it okay to override a deprecated method with another signature when not using
@override?My tendency is yes; see
testDeprecatedOverriddenMethod.Is it desirable that Mypy emits an error for
C.fin the following case (as it currently does)?My tendency is that no error should be emitted for
C.f. I did not change this, but it appears to be simple.I am asking because:
PEP 698 does not mention
@overload. In Mypy, a single@overridefor any overload item or the implementation affects the whole overloaded method. This was decided here without any discussions I know of and will likely result in some inconsistencies with the overload item-specific implementation of@deprecated:I think it would be favourable to neither emit deprecation nor signature-incompatible notes in the given example. (I did not investigate how hard it would be to implement this.
overrideanddeprecatedare properties of symbols. But maybe we could just remove some items before doing the checks.)