DEPR: deprecate Matlab-like tic/tac/toc/loop_timer timers (#786)#833
DEPR: deprecate Matlab-like tic/tac/toc/loop_timer timers (#786)#833Builder106 wants to merge 1 commit into
Conversation
) Emit a DeprecationWarning from the public `tic`, `tac`, `toc` and `loop_timer` functions, pointing users to the modern `Timer` context manager and `timeit` function added in QuantEcon#783/QuantEcon#794. Removal is targeted for v0.12.0. - `__Timer__.loop_timer` now calls its own methods (`self.tic`/`tac`/ `toc`) instead of the public wrappers, so a single `loop_timer` call emits exactly one warning rather than one per run. - The warning uses `stacklevel=3` so it is attributed to the user's call site rather than the wrapper. - Added `.. deprecated:: 0.12.0` directives to the module and the affected docstrings. - Added tests asserting each function warns, that `loop_timer` warns only once, and that the warning points at the caller. Note: the original issue mentioned removal in 0.9.*, but the library is already at v0.11.2, so this targets v0.12.0 instead.
|
Hi @Builder106 — this is really cleanly done, thanks! 🙏 The On your open question about the target version: let's plan to remove these in v1.0 rather than 0.12.0. There's no harm in carrying them with the deprecation notice in the meantime, and v1.0 is the natural point to drop the Matlab-style API. One small distinction while you make that change: the
That way the rendered docs read "deprecated since 0.12.0, will be removed in 1.0", which is the conventional phrasing. Everything else looks great — happy to approve once that's tweaked. Thanks again! 😊 |
Closes #786 (Step 1).
Now that the
Timercontext manager (#783) andtimeit(#794) are merged, this implements Step 1 of #786: emit aDeprecationWarningfrom the legacy Matlab-like timers, steering users to the modern API. Step 2 (removing the functions) can follow in the targeted release.Changes
tic,tac,toc, andloop_timernow emit aDeprecationWarning.tic/tac/tocpoint to theTimercontext manager;loop_timerpoints totimeit.stacklevel=3, so it's attributed to the user's call site rather than the internal wrapper.__Timer__.loop_timernow calls its own methods (self.tic()/self.tac()/self.toc()) instead of the public wrapper functions. This is functionally identical but ensures a singleloop_timercall emits exactly one warning instead of one per run... deprecated:: 0.12.0directives to the module docstring and the affected function/method docstrings.Tests
TestDeprecationclass asserting each function raisesDeprecationWarning, thatloop_timerwarns only once (no nested warnings), and that the warning points at the caller's file.33 passed).Note on target version
The issue text mentions removal for
0.9.*, but the library is already at v0.11.2, so the deprecation message and directives target v0.12.0. Happy to adjust to whatever removal version the maintainers prefer.