[py-dev] py.log suggestion

François Pinard pinard at iro.umontreal.ca
Sun Oct 16 18:37:04 CEST 2005


> [François Pinard]

> > > >     if trace.dossier:
> > > >         diagnostic = prepare_diagnostic_information()
> > > >         trace.dossier(diagnostic)

> >      if callable(trace.dossier):
> >          diagnostic = prepare_diagnostic_information()
> >          trace.dossier(diagnostic)

[holger krekel]

> i was thinking of just

>     trace.dossier(prepare_diagnostic_information)

> actually.  If there is no consumer then this would not call the
> callable.  Does that make sense to you?

Of course, a lot.  This is a better idea, that would yield cleaner code.

> (we could additionally pass any remaining arguments to the callable
> but that might be hard to conceptually define nicely).

Could not the producer prototype be a mere:

   producer(message, *args, **kws)

It could implement something like:

    [...]
    if any_consumer_besides_None:
        if callable(message):
            text = message(*args, **kws)
        elif args:
            assert not kws
            text = message % args
        elif kws:
            text = message % kws
        else:
            text = message
    [...]

yielding the usual paradigm that message may be a format, for which
interpolation does not uselessly occur.  Also, the format could use
%(keyword)s, with keywords given while calling the producer.

About if the `assert' should be there or not rather depends on how
forgiving py.log wants to be.  I probably yield on the stricter side,
also considering that format errors already raise exceptions.

-- 
François Pinard   http://pinard.progiciels-bpi.ca


More information about the py-dev mailing list