This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author roippi
Recipients LambertDW, belopolsky, georg.brandl, peter.otten, pitrou, rhettinger, roippi, stefanv, steven.daprano
Date 2014-08-18.21:37:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1408397852.72.0.453959015684.issue2527@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-08-18 21:37:32roippisetrecipients: + roippi, georg.brandl, rhettinger, peter.otten, belopolsky, pitrou, LambertDW, steven.daprano, stefanv
2014-08-18 21:37:32roippisetmessageid: <1408397852.72.0.453959015684.issue2527@psf.upfronthosting.co.za>
2014-08-18 21:37:32roippilinkissue2527 messages
2014-08-18 21:37:32roippicreate