Re: Optimizing methods away or not?

2008-12-14 Thread Terry Reedy
Steven D'Aprano wrote: I have a class with a method meant to verify internal program logic (not data supplied by the caller). Because it is time-consuming but optional, I treat it as a complex assertion statement, and optimize it away if __debug__ is false: class Parrot: def __init__(self

Re: Optimizing methods away or not?

2008-12-14 Thread Arnaud Delobelle
Steven D'Aprano writes: > On Sun, 14 Dec 2008 10:52:25 +, Arnaud Delobelle wrote: > >> You could also not use the metaclass and use post_verify as a decorator > > Except that self.verify doesn't exist if __debug__ is false. OK I wrote this as an afterthought. I'm, sure it's not beyond your

Re: Optimizing methods away or not?

2008-12-14 Thread Steven D'Aprano
On Sun, 14 Dec 2008 10:52:25 +, Arnaud Delobelle wrote: > You could also not use the metaclass and use post_verify as a decorator Except that self.verify doesn't exist if __debug__ is false. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Optimizing methods away or not?

2008-12-14 Thread Arnaud Delobelle
Steven D'Aprano writes: > I have a class with a method meant to verify internal program logic (not > data supplied by the caller). Because it is time-consuming but optional, > I treat it as a complex assertion statement, and optimize it away if > __debug__ is false: > > class Parrot: > def

Re: Optimizing methods away or not?

2008-12-14 Thread Steven D'Aprano
On Sun, 14 Dec 2008 09:19:45 +, Marc 'BlackJack' Rintsch wrote: > On Sun, 14 Dec 2008 07:41:55 +, Steven D'Aprano wrote: > >> I have a class with a method meant to verify internal program logic >> (not data supplied by the caller). Because it is time-consuming but >> optional, I treat it

Re: Optimizing methods away or not?

2008-12-14 Thread Marc 'BlackJack' Rintsch
On Sun, 14 Dec 2008 09:19:45 +, Marc 'BlackJack' Rintsch wrote: > class Parrot: > def __init__(self, *args): > print "Initialising instance..." > assert self.verify() Here I meant ``assert self._verify()`` of course. > def _verify(self): > print "Verifying..."

Re: Optimizing methods away or not?

2008-12-14 Thread Marc 'BlackJack' Rintsch
On Sun, 14 Dec 2008 07:41:55 +, Steven D'Aprano wrote: > I have a class with a method meant to verify internal program logic (not > data supplied by the caller). Because it is time-consuming but optional, > I treat it as a complex assertion statement, and optimize it away if > __debug__ is fal

Re: Optimizing methods away or not?

2008-12-14 Thread James Stroud
Steven D'Aprano wrote: class Parrot: def __init__(self, *args): print "Initialising instance..." if __debug__: self.verify() # check internal program state, not args if __debug__: def verify(self): print "Verifying..." +1 It looks good to

Optimizing methods away or not?

2008-12-13 Thread Steven D'Aprano
I have a class with a method meant to verify internal program logic (not data supplied by the caller). Because it is time-consuming but optional, I treat it as a complex assertion statement, and optimize it away if __debug__ is false: class Parrot: def __init__(self, *args): print "