diff options
author | Matthew Brett <matthew.brett@gmail.com> | 2009-07-23 01:11:16 +0000 |
---|---|---|
committer | Matthew Brett <matthew.brett@gmail.com> | 2009-07-23 01:11:16 +0000 |
commit | 782ad5967a84077b8632730b392f8450a44a1a36 (patch) | |
tree | e3132b73288f1d29cb838ff6b567e1da7b053cb9 /numpy/doc | |
parent | 377ade5f3a2d2b780743b8992d29b0e6ba037f53 (diff) | |
download | numpy-782ad5967a84077b8632730b392f8450a44a1a36.tar.gz |
Small edits to subclassing doc to make classes more explicit
Diffstat (limited to 'numpy/doc')
-rw-r--r-- | numpy/doc/subclassing.py | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/numpy/doc/subclassing.py b/numpy/doc/subclassing.py index 6f364a30d..0cbec4520 100644 --- a/numpy/doc/subclassing.py +++ b/numpy/doc/subclassing.py @@ -180,25 +180,25 @@ The role of ``__array_finalize__`` ``__array_finalize__`` is the mechanism that numpy provides to allow subclasses to handle the various ways that new instances get created. -Renenber that subclass instances can come about in these three ways: +Remember that subclass instances can come about in these three ways: -#. explicit constructor call (``obj = MySubClass(params)``. This will call the usual - sequence of ``MySubClass.__new__`` then ``MySubClass.__init__``. +#. explicit constructor call (``obj = MySubClass(params)``). This will + call the usual sequence of ``MySubClass.__new__`` then (if it exists) + ``MySubClass.__init__``. #. :ref:`view-casting` #. :ref:`instance-slicing` Our ``MySubClass.__new__`` method only gets called in the case of the -explicit constructor call, so we can't rely on ``__new__`` or -``__init__`` to deal with the view casting or slicing. It turns out -that ``__array_finalize__`` *does* get called for all three methods of -object creation, so this is where our object creation housekeeping -usually goes. - -``MySubClass.__array_finalize__`` is called for all of these instance -creation paths. This is because it is called from ``ndarray.__new__``, -when ``MySubClass`` as the first (class) argument. The reason -``ndarray.__new__(MySubClass,...)`` gets called is different for the -three cases above. +explicit constructor call, so we can't rely on ``MySubClass.__new__`` or +``MySubClass.__init__`` to deal with the view casting or slicing. It +turns out that ``MySubClass.__array_finalize__`` *does* get called for +all three methods of object creation, so this is where our object +creation housekeeping usually goes. + +In fact ``MySubClass.__array_finalize__`` is called from +``ndarray.__new__``, when ``MySubClass`` is the first (class) argument +to ``ndarray.__new__``. The reason ``ndarray.__new__(MySubClass,...)`` +gets called is different for the three cases above. * For the explicit constructor call, our subclass will need to create a new ndarray instance of its own class. This will require a call to |