You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is this possible?
if possible. would it be useful?
class A:
@no_inherit
def method_one(self, x):
# implementation of method_one
@no_override
def method_two(self, x):
# implementation of method_two
def method_three(self, x):
# implementation of method_three
class B(A):
def method_two(self, x):
# changed implementation of method_two
but method_one does not get inherited,
and
for method_two, the changed implementation does not work, the implementation described in class A for method_two stays for all the child classes.
The text was updated successfully, but these errors were encountered:
For @no_inherit I could be missing something but I don't really see any use. Rather than preventing the method from being inherited, you can just not use it if you don't want/need it. If you want to force a method to be redefined you may want an abc (https://peps.python.org/pep-3119/)).
If you wanted to enforce either of these you could probably write a metaclass that did, although I can't think of any use cases where it should be necessary.
Uh oh!
There was an error while loading. Please reload this page.
is this possible?
if possible. would it be useful?
but
method_one
does not get inherited,and
for
method_two
, the changed implementation does not work, the implementation described inclass A
formethod_two
stays for all the child classes.The text was updated successfully, but these errors were encountered: