I'm trying to identify if a class that i received via an argument has a user defined __init__
function in the class that was passed. Not in any super class.
class HasInit(object):
def __init__(self):
pass
class NoInit(object):
pass
class Base(object):
def __init__(self):
pass
class StillNoInit(Base):
pass
def has_user_defined_init_in(clazz):
return True if # the magic
assert has_user_defined_init_in(HasInit) == True
assert has_user_defined_init_in(NoInit) == False
assert has_user_defined_init_in(StillNoInit) == False
I think this will work:
def has_user_defined_init_in(clazz):
return "__init__" in clazz.__dict__
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With