-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
@override
warnings are silenced by accidentally type-annotating override
#15293
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
Comments
Shorter repro: The trouble is that -override: Callable[[F], F]
+override: Callable[[F, int], F] then you'd get
so the right way to think about it is -(1) remote reference
+(1) local declaration
+(2) assignment and since we don't track the value throughout assignments, the Does it make sense to either
|
Doesn't it work as expected without the I would write it like this: from typing import Any, Callable, TypeVar, TYPE_CHECKING
F = TypeVar("F", bound=Callable[..., Any])
if TYPE_CHECKING:
from typing_extensions import override
else:
def override(method: F, /) -> F:
return method
class ClassA:
...
class ClassB(ClassA):
@override
def this_should_error(self) -> None:
pass
reveal_type(ClassB.this_should_error) https://mypy-play.net/?mypy=master&python=3.11&gist=f8cef5ea618b97668d941510ad211550 ...which seems to work? |
Yes, it does - that's why I wrote "accidental" in the title. The The point of this issue not to improve my code, but to make you aware that by typing |
Yeah, I think this is a won't fix. As ikonst says, this looks like something that could get rebound. pyright's behaviour is similar, except that it issues a tmke8's suggestion of |
Bug Report
I am thinking about using
override
on Python < 3.12 without having to havetyping_extensions
as a forced run-time dependency. I am using a conditional import for this, which I had previously also done foroverrides.override
, see #13914. However, when I leave this type annotation in place fortyping_extensions.override
, all@override
warnings are gone.To Reproduce
https://gist.github.com/mypy-play/74cf551a06f0cc5b56ddc8cc96708ab8
Expected Behavior
Mypy error about
this_should_error
Actual Behavior
No error
Your Environment
The text was updated successfully, but these errors were encountered: