-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
bpo-31803: time.clock() now emits a DeprecationWarning #4020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use self.assertWarns()? I think support.check_warnings() is for 2.7 code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
time.clock() and time.get_clock_info('clock') now emit a DeprecationWarning warning.
https://bugs.python.org/issue31803