darkgaze darkgaze - 3 months ago 9
Python Question

Know if child class has implemented a parent method

I have a base class class X, and a child class Y which could reimplement or not a method from the base class X.

I pass the name of the child class as a variable to functions.

Inside those functions I need to test if that class passed has implemented or not some methods from it's base class.

(I can't use hasattr(childClassName.methodName) since it always returns True)

Answer

use to compare:

 getattr(className, 'methodName') is getattr(className, 'method')

if false, the method was overridden