From 782ad5967a84077b8632730b392f8450a44a1a36 Mon Sep 17 00:00:00 2001 From: Matthew Brett Date: Thu, 23 Jul 2009 01:11:16 +0000 Subject: Small edits to subclassing doc to make classes more explicit --- numpy/doc/subclassing.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'numpy/doc') 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 -- cgit v1.2.1