From: Colin J. W. <cj...@sy...> - 2004-05-05 23:00:54
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <title></title> </head> <body text="#000000" bgcolor="#ffffff"> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <title></title> <br> <br> Todd Miller wrote:<br> <blockquote type="cite" cite="mid...@ha..."> <pre wrap="">On Wed, 2004-05-05 at 16:27, Colin J. Williams wrote: </pre> <blockquote type="cite"> <pre wrap="">It would help to have some documentation on the purpose and usage of the class UsesOpPriority and its variable op_priority. </pre> </blockquote> <pre wrap=""><!----></pre> </blockquote> Todd,<br> <br> Thanks for this, perhaps it could be added to the pdf . I like the basic idea.<br> <blockquote type="cite" cite="mid...@ha..."> <pre wrap="">The basic idea was that NumArray subclasses which want to use numarray operators would: 1. subclass from UsesOpPriority </pre> </blockquote> UsesOpPriority has no methods and thus, to access the methods of NumArray, it would appear to be necessary to subclass from NumArray.<br> <blockquote type="cite" cite="mid...@ha..."> <pre wrap=""> 2. set a class level op_priority > 0. NumArrays have op_priority 0, higher priorities are given "precedence". Thus, given A=NumArray(...) and B=NumArraySubclass(...), and A.op_priority==0 and B.op_priority==1, then: A+B would execute as B.__radd__(A) rather than A.__add__(B) and hence the type(A+B) could be NumArraySubclass rather than NumArray. Different subclasses could use higher or lower op_priorities to perform the same kind of operator resolution among themselves. </pre> </blockquote> I wonder about the desirability of having different levels of priority for the same level of subclassing and am puzzled that a float variable is used for the priority.<br> <br> It would nice if this depth could be determined automatically. Perhaps something like the script below could be used.<br> <br> Colin W.<br> <blockquote type="cite" cite="mid...@ha..."> <pre wrap=""> Todd </pre> </blockquote> # tClassing.py<br> <br> class A:<br> def __init__(self):<br> self.p= 0<br> def prior(self):<br> self.p+= 1<br> class B(A):<br> def __init__(self):<br> A.__init__(self)<br> self.prior()<br> class C(B):<br> def __init__(self):<br> B.__init__(self)<br> self.prior()<br> <br> print A().p<br> print B().p<br> c= C()<br> print 'Priority for C methods:', c.p<br> </body> </html> |