I've come across some behavior in Python 3.7 that I don't understand when subclassing Exception
I've been using Python for a long time and I've always had the understanding that base class constructors are not implicit and must be called explicitly.
For example, the below behavior is consistent with my understanding, since the constructor for A
is never called x
will not be defined.
class A():
def __init__(self, x):
self.x = x
class B(A):
def __init__(self, x):
pass
b = B(1)
print(b.x)
AttributeError: 'B' object has no attribute 'x'
But in the below example, I don't understand how the Exception
base class receives the message hello
when I don't explicitly provide it to the base class constructor.
class E(Exception):
def __init__(self, msg):
# don't do anything with msg
pass
raise E("hello")
__main__.E: hello