Python Forum
Determine whether a method was overridden
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Determine whether a method was overridden
#6
I think this is what you want:

class Base(object):

    def f(self):
        raise NotImplementedError()
 
    @classmethod
    def has_f(cls):
        return cls.f != Base.f
 
class Derived(Base):

    def f(self):
        pass

class Inherit(Base):
    
    def g(self):
        pass

if __name__ == '__main__':
    print(Base.has_f())
    print(Derived.has_f())
    print(Inherit.has_f())
This returns True if the method has been overridden. The classmethod decorator makes the class be passed as the first parameter, not the instance.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: Determine whether a method was overridden - by ichabod801 - Nov-14-2016, 09:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variables being overridden to initial values. p2bc 6 3,799 Oct-10-2020, 09:03 PM
Last Post: p2bc
  How to determine pen color from an image? robie972003 2 3,257 Mar-24-2019, 10:06 PM
Last Post: robie972003
  determine if an number is in a list Dbeah 7 5,057 Nov-06-2018, 12:11 PM
Last Post: buran
  determine if an number is in a list Dbeah 1 2,791 Nov-04-2018, 04:50 PM
Last Post: stullis
  how to determine if an object is a number Skaperen 6 5,275 Jul-11-2018, 08:18 PM
Last Post: Skaperen
  How Do I Determine indentation in AST? jimo 3 5,494 Jul-01-2018, 04:25 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020