From 6535ec6b95d3b3978fe52ea31523c7bd14f4e95b Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Thu, 25 Jul 2019 22:17:22 -0400 Subject: use timeit.default_timer instead of time.clock() / time.time() Replaced usage of time.clock() on windows as well as time.time() elsewhere for microsecond timestamps with timeit.default_timer(), as time.clock() is being removed in Python 3.8. Pull request courtesy Christoph Reiter. Fixes: #301 Closes: #302 Pull-request: https://github.com/sqlalchemy/mako/pull/302 Pull-request-sha: a706e952727337702692fd1d8369d259e1600d6e Change-Id: I24e2cd3d2c02323a6fa2b063e86cabe555df2036 --- doc/build/unreleased/301.rst | 8 ++++++++ mako/compat.py | 6 ------ mako/util.py | 5 +++-- tox.ini | 1 + 4 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 doc/build/unreleased/301.rst diff --git a/doc/build/unreleased/301.rst b/doc/build/unreleased/301.rst new file mode 100644 index 0000000..7e9f1d2 --- /dev/null +++ b/doc/build/unreleased/301.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: bug, py3k, windows + :tickets: 301 + + Replaced usage of time.clock() on windows as well as time.time() elsewhere + for microsecond timestamps with timeit.default_timer(), as time.clock() is + being removed in Python 3.8. Pull request courtesy Christoph Reiter. + diff --git a/mako/compat.py b/mako/compat.py index a3b1fd0..2444cad 100644 --- a/mako/compat.py +++ b/mako/compat.py @@ -6,7 +6,6 @@ import json # noqa import sys -import time py3k = sys.version_info >= (3, 0) py33 = sys.version_info >= (3, 3) @@ -141,11 +140,6 @@ except ImportError: else: import dummy_thread as thread # noqa -if win32 or jython: - time_func = time.clock -else: - time_func = time.time - try: from functools import partial except: diff --git a/mako/util.py b/mako/util.py index 4f1426d..07f7531 100644 --- a/mako/util.py +++ b/mako/util.py @@ -9,6 +9,7 @@ import collections import operator import os import re +import timeit from mako import compat @@ -180,7 +181,7 @@ class LRUCache(dict): def __init__(self, key, value): self.key = key self.value = value - self.timestamp = compat.time_func() + self.timestamp = timeit.default_timer() def __repr__(self): return repr(self.value) @@ -191,7 +192,7 @@ class LRUCache(dict): def __getitem__(self, key): item = dict.__getitem__(self, key) - item.timestamp = compat.time_func() + item.timestamp = timeit.default_timer() return item.value def values(self): diff --git a/tox.ini b/tox.ini index 8611507..45b48d1 100644 --- a/tox.ini +++ b/tox.ini @@ -29,6 +29,7 @@ deps= flake8-builtins flake8-docstrings flake8-rst-docstrings + pydocstyle<4.0.0 # used by flake8-rst-docstrings pygments commands = flake8 ./mako/ ./test/ setup.py --exclude test/templates,test/foo -- cgit v1.2.3