Email Re: [Python-projects] return statement in __init__

subject
Re: [Python-projects] return statement in __init__
date
2005/04/18 11:11
On Monday, April 18, 2005 Sylvain Thénault - Sylvain.Thenault@logilab.fr wrote:
> IMHO it's a bad habit to have a return in __init__, valid or not valid.
> Maybe should I turn the error into a warning when it's a "legal" return,
> but I'm really not sure here. 

I have a thread profiler. Instead of checking in each thread if
profiling is enabled, I check it in the thread profiler constructor.
If profiling is disabled, this object simply ignores all requests. I
could have used an "if" instead of "return", but this looked more
natural. Anyway, this is the only place where I use a return statement
in __init__, so you may be right.

class ThreadProfiler(object):

    def __init__(self, name):
        Log.root.trace()

        self.__enabled = Flags().profile
        if not self.__enabled:
            return

        import hotshot
        filename = Path.GetAppFolderFile(Files.profilelog % name)
        self.__profiler = hotshot.Profile(filename)

        ProfilerManager().AttachProfiler(self)


_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects