-
Notifications
You must be signed in to change notification settings - Fork 258
Provide guidance on PEP 698's strict enforcement feature of typing.override #1376
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
Cc. @stroxler |
On the same topic, consider this bad code class A:
def f(self, x: int) -> None:
pass
class B:
def f(self, x: int) -> None:
pass
class C(A, B):
pass In Normally, if class SomeInterface:
def f(self, x: int) -> None:
raise NotImplementedError
class A(SomeInterface):
@override
def f... |
I would very much favor that |
I don't have as much of an opinion about multiple inheritance; that's a messy problem that I haven't thought too much about. In many cases preexisting conventions (which vary a bit per type checker) about method signature type compatibility might detect the problem - for example if That said, I'm not sure Pyre would catch this with compatibility checks- I suspect that we only verify compatibility on actual definitions in Regardless, the idea certainly has merit. One potential reason not to do that would be that normal strict-override-errors should be trivial to autofix by injecting an We probably wouldn't include this in Pyre for that reason, since we need to be able to auto-apply |
I'm fine exempting As for the multiple inheritance example, I don't think that falls under the purview of PEP 698. Any class in Python can, in theory, be used as a base class for multiple inheritance. It would be unreasonable and inappropriate to expect that an author of a class anticipate the need to mark their methods with an |
PEP 698 (
typing.override
) suggests that type-checkers provide a strict enforcement option that would mark method overrides. However, no guidance is provided about the methods__init__
and__new__
. These methods are always implicit overrides (fromobject
method). These method do not obey LSP (so their signature doesn't depend on any superclass), which means that override decoration only verifies that you haven't misspelled the method. Should they be exempt from this strict check?(I'm not convinced one way or the other, but it would be nice to have some guidance on this.)
CC'ing @erictraut because we had a brief discussion about this.
The text was updated successfully, but these errors were encountered: