bpo-31803: time.clock() now emits a DeprecationWarning#4020
bpo-31803: time.clock() now emits a DeprecationWarning#4020vstinner merged 5 commits intopython:masterfrom vstinner:clock_warn
Conversation
bpo-31803: time.clock() and time.get_clock_info('clock') now emit a DeprecationWarning warning.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Did you forgot to add a deprecation in get_clock_info('clock')?
Lib/test/test_time.py
Outdated
| for name in clocks: | ||
| info = time.get_clock_info(name) | ||
| with warnings.catch_warnings(): | ||
| warnings.filterwarnings("ignore", "", DeprecationWarning) |
There was a problem hiding this comment.
Add a comment, otherwise we can forgot why this was added.
But I prefer moving all the code from the loop body to a local function and calling it multiple times.
def test(name):
...
test('perf_counter')
test('process_time')
test('time')
if hasattr(time, 'monotonic'):
test('monotonic')
with self.assertWarns(DeprecationWarning):
test('clock')This silences a warning only for clock, tests that a warning for clock is raised, and in case of test failure the traceback contains a line with a timer's name.
There was a problem hiding this comment.
I changed the code to make the warning check explicit.
Moreover, hasattr(time, 'monotonic') test is outdated: time.monotonic() is always available since Python 3.5. I also fixed that.
Explicitly check that get_clock_info('clock') emits a
DeprecationWarning.
Remove also hasattr(time, 'monotonic') since time.monotonic() is now
always available since Python 3.5.
get_clock_info('clock') also emits a DeprecationWarning. I modified pyclock() which is used by time.clock() and time.get_clock_info('clock'). I just modified test_get_clock_info() to ensure that time.get_clock_info('clock') raises a warning, instead of ignoring the warning. |
Lib/test/test_time.py
Outdated
|
|
||
| def test_clock(self): | ||
| time.clock() | ||
| with support.check_warnings(('time.clock has been deprecated', |
There was a problem hiding this comment.
Why not use self.assertWarns()? I think support.check_warnings() is for 2.7 code.
There was a problem hiding this comment.
I didn't know assertWarns(). Why do we still have support.check_warnings()? check_warnings() docstring doesn't mention assertWarns(). It's still widely used in the test suite:
haypo@selma$ grep check_warnings Lib/test/test*py|wc -l
115
Anyway, I modified my PR to use assertWarns().
There was a problem hiding this comment.
Maybe all this is inherited from Python 2. Or other developers don't know assertWarns(). Or check_warnings() can be used in the cases when assertWarns() can't (not this case).
time.clock() and time.get_clock_info('clock') now emit a DeprecationWarning warning.
https://bugs.python.org/issue31803