Message225508
Attached is a patch that adds a 'global' kwarg to the Timeit constructor, which does pretty much what it says on the tin: specifies a global namespace that exec() will use.
I originally had a 'locals' arg as well (to mirror the signature of eval/exec), but realized that the local vars I was passing to exec were not available to the inner function. Reason: the timeit module compiles/execs a *closure*, and closed-over variables and exec() simply do not play nicely. Possible workarounds were to munge locals() into the globals() dict, or to somehow inject the variables in the locals dict into the closure. I found neither of these options superior to simply not including a locals argument, for reasons of Least Surprise and maintainability.
Patch includes some basic tests and documentation. I am particularly uncomfortable with writing docs so those very likely need some polish. |
|
Date |
User |
Action |
Args |
2014-08-18 21:37:32 | roippi | set | recipients:
+ roippi, georg.brandl, rhettinger, peter.otten, belopolsky, pitrou, LambertDW, steven.daprano, stefanv |
2014-08-18 21:37:32 | roippi | set | messageid: <1408397852.72.0.453959015684.issue2527@psf.upfronthosting.co.za> |
2014-08-18 21:37:32 | roippi | link | issue2527 messages |
2014-08-18 21:37:32 | roippi | create | |
|