Open DetachHead opened 3 weeks ago
Note Unlike Java abstract methods, these abstract methods may have an implementation. This implementation can be called via the
super()
mechanism from the class that overrides it. This could be useful as an end-point for a super-call in a framework that uses cooperative multiple-inheritance.
That's got to be a peak level of Python idiocy. I fully support this. Ban it 🔨
alternativly, could we require that it explicitly raises an exception:
from abc import ABC, abstractmethod
from typing import override
class A(ABC):
@abstractmethod
def foo(self) -> int: ...
class D:
def foo(self) -> int:
return 1
class C(D):
@override
def foo(self) -> int:
return super().foo()
# mro = B, C, A, D
class B(C, A, D): pass
_ = B().foo() + 1 # no error, None at runtime
maybe no implementation, or exception, your choice.
I vote for no implementation. It's the most idiomatic choice IMO. Abstract methods are supposed to be abstract lol. I don't know if there are any other programming languages that allow this (they shouldn't).
other programming languages tend to throw an error if you somehow end up calling an abstract method, python just returns None
apparently this is intentionally allowed but i think it's stupid so there should be an option to ban it