Skip to content

Commit 8a46bda

Browse files
committed
cleaned up super() discusssion a bit...
1 parent 8331752 commit 8a46bda

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ slides_sources/build
1515

1616
*.pyc
1717
build/
18+
19+
.ipynb_checkpoints

slides_sources/source/advanced_oo.rst

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Multiple Inheritance
1414
====================
1515

1616

17-
Pulling methoda from more than one class
17+
Pulling methods from more than one class
1818

1919

2020
multiple inheritance
@@ -220,7 +220,7 @@ same as::
220220
A.__init__()
221221

222222
| You may not want that --
223-
| demo: ``code /super_test.ipnb``
223+
| demo: ``Examples/week-06-OO/super_test.ipnb``
224224
225225

226226
super() mechanics
@@ -243,6 +243,8 @@ which usually is somethign like:
243243
So why in the world do you need to specify both `B` (the type), and
244244
`self` (the instance?)
245245

246+
.. nextslide::
247+
246248
First: Python 3 has cleaned this up, it's just:
247249

248250
.. code-block:: python
@@ -251,7 +253,9 @@ First: Python 3 has cleaned this up, it's just:
251253
def a_method(self, *args, **kwargs)
252254
super().a_method(*args, **kwargs)
253255
254-
In py3. But in Python2, super was tacked on, so the additonal info is
256+
In py3.
257+
258+
In Python2, super was tacked on, so the additonal info is
255259
needed, and it does have the advantage of being explicit about the two
256260
inputs to the computation (the mro of self and the current position in
257261
the mro).
@@ -261,21 +265,6 @@ actually be an *instance* of B -- it could be a subclass.
261265

262266
That's why both need to be specified.
263267

264-
**But I'm specifying the class name twice, still!**
265-
266-
The first argument to ``super()`` must be the class object that you want
267-
the superclass of -- that is the class you are currently defining. But
268-
you don't need to write that specifically -- you can use its
269-
``__class__`` magic method:
270-
271-
.. code-block:: python
272-
273-
class B(A):
274-
def a_method(self, *args, **kwargs)
275-
super(self.__class__, self).a_method(*args, **kwargs)
276-
277-
278-
That way you only specify the superclass in one place.
279268

280269
More detail about super()
281270
-------------------------
@@ -334,7 +323,6 @@ and call super like
334323
335324
336325
337-
338326
Wrap Up
339327
---------
340328

0 commit comments

Comments
 (0)