Skip to content

Instantly share code, notes, and snippets.

@jerome-diver
Last active May 16, 2019 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerome-diver/9dd5ba5e9ea0a49992a19ece9b273405 to your computer and use it in GitHub Desktop.
Save jerome-diver/9dd5ba5e9ea0a49992a19ece9b273405 to your computer and use it in GitHub Desktop.
error unexpected (missundertsand inherited class in python 3)
In [129]: class A:
def __init__(self, x):
super().__init__(x)
self._x = x
self._a_var = "Variable A"
@property
def a_var(self, x):
return self._a_var
class B:
def __init__(self, x):
super().__init__(x)
self._b_var = "Variable B"
self._x = x
@property
def b_var(self):
return self._b_var
class C(B,A):
def __init__(self, x):
super().__init__(x)
self._c_var = "Variable_c"
self._x = x
class D(C):
def __init__(self, x):
super().__init__(x)
self._d_var = "VARIABLE D"
In [130]: test_d = D("THE X arg")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-130-f60076053a06> in <module>
----> 1 test_d = D("THE X arg")
<ipython-input-129-54ad04b6d867> in __init__(self, x)
22 class D(C):
23 def __init__(self, x):
---> 24 super().__init__(x)
25 self._d_var = "VARIABLE D"
26
<ipython-input-129-54ad04b6d867> in __init__(self, x)
17 class C(B,A):
18 def __init__(self, x):
---> 19 super().__init__(x)
20 self._c_var = "Variable_c"
21 self._x = x
<ipython-input-129-54ad04b6d867> in __init__(self, x)
9 class B:
10 def __init__(self, x):
---> 11 super().__init__(x)
12 self._b_var = "Variable B"
13 self._x = x
<ipython-input-129-54ad04b6d867> in __init__(self, x)
1 class A:
2 def __init__(self, x):
----> 3 super().__init__(x)
4 self._x = x
5 self._a_var = "Variable A"
TypeError: object.__init__() takes exactly one argument (the instance to initialize)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment