Consider the following code. Note the comments in particular:
from abc import ABC, abstractmethod # func1 MUST be overridden # func2 may be overridden class Class1(ABC): @abstractmethod def func1(self): pass #any code here is useless def func2(self): print('fallback message') # func1, func2 may be overridden # @abstractmethod does nothing # Effectively same as Class3, Class4 class Class2(): @abstractmethod def func1(self): pass def func2(self): pass # func1, func2 may be overridden # Inheriting from ABC does nothing # Effectively same as Class4, Class2 class Class3(ABC): def func1(self): pass def func2(self): pass # func1, func2 may be overridden # Effectively same as Class3, Class2 class Class4(): def func1(self): pass def func2(self): pass
Assuming my comments are valid, am I correct in thinking that the @abstractmethod decorator only makes sense when used in conjunction with an ABC class? (i.e., Class1)
submitted by /u/QuasiEvil
[link] [comments]
r/learnpython Consider the following code. Note the comments in particular: from abc import ABC, abstractmethod # func1 MUST be overridden # func2 may be overridden class Class1(ABC): @abstractmethod def func1(self): pass #any code here is useless def func2(self): print(‘fallback message’) # func1, func2 may be overridden # @abstractmethod does nothing # Effectively same as Class3, Class4 class Class2(): @abstractmethod def func1(self): pass def func2(self): pass # func1, func2 may be overridden # Inheriting from ABC does nothing # Effectively same as Class4, Class2 class Class3(ABC): def func1(self): pass def func2(self): pass # func1, func2 may be overridden # Effectively same as Class3, Class2 class Class4(): def func1(self): pass def func2(self): pass Assuming my comments are valid, am I correct in thinking that the @abstractmethod decorator only makes sense when used in conjunction with an ABC class? (i.e., Class1) submitted by /u/QuasiEvil [link] [comments]
Consider the following code. Note the comments in particular:
from abc import ABC, abstractmethod # func1 MUST be overridden # func2 may be overridden class Class1(ABC): @abstractmethod def func1(self): pass #any code here is useless def func2(self): print('fallback message') # func1, func2 may be overridden # @abstractmethod does nothing # Effectively same as Class3, Class4 class Class2(): @abstractmethod def func1(self): pass def func2(self): pass # func1, func2 may be overridden # Inheriting from ABC does nothing # Effectively same as Class4, Class2 class Class3(ABC): def func1(self): pass def func2(self): pass # func1, func2 may be overridden # Effectively same as Class3, Class2 class Class4(): def func1(self): pass def func2(self): pass
Assuming my comments are valid, am I correct in thinking that the @abstractmethod decorator only makes sense when used in conjunction with an ABC class? (i.e., Class1)
submitted by /u/QuasiEvil
[link] [comments]