Re: decorator needs access to variables where it is used.

2019-10-12 Thread Serhiy Storchaka
09.10.19 14:02, Chris Angelico пише: The decorator has full access to the function object, including a reference to that function's module globals. def trace(func): log = func.__globals__["log"] ... proceed as before As long as you can depend on "log" always being a module-level (glob

Re: decorator needs access to variables where it is used.

2019-10-10 Thread Antoon Pardon
On 9/10/19 13:02, Chris Angelico wrote: > On Wed, Oct 9, 2019 at 9:53 PM Antoon Pardon wrote: >> I have some logging utilities so that when I write library code, I just use >> the following. >> >> from logutil import Logger >> >> log = Logger(__name__) > Are you always absolutely consistent with

Re: decorator needs access to variables where it is used.

2019-10-09 Thread Peter Otten
Antoon Pardon wrote: > I have some logging utilities so that when I write library code, I just > use the following. > > from logutil import Logger > > log = Logger(__name__) If logutil is under your control you can make log a callable object with a tracing method: [logutil.py] class Logger:

Re: decorator needs access to variables where it is used.

2019-10-09 Thread Chris Angelico
On Wed, Oct 9, 2019 at 9:53 PM Antoon Pardon wrote: > > I have some logging utilities so that when I write library code, I just use > the following. > > from logutil import Logger > > log = Logger(__name__) Are you always absolutely consistent with this? Do you always have it as a module-level v