diff --git a/vyper/compiler/input_bundle.py b/vyper/compiler/input_bundle.py index 27170f0a56..d4132cad50 100644 --- a/vyper/compiler/input_bundle.py +++ b/vyper/compiler/input_bundle.py @@ -48,6 +48,11 @@ class _NotFound(Exception): pass +# an opaque object which consumers can get/set attributes on +class _Cache(object): + pass + + # an "input bundle" to the compiler, representing the files which are # available to the compiler. it is useful because it parametrizes I/O # operations over different possible input types. you can think of it @@ -66,9 +71,9 @@ def __init__(self, search_paths): self._source_id_counter = 0 self._source_ids: dict[PathLike, int] = {} - # this is a little bit cursed, but it allows consumers to cache data that - # share the same lifetime as this input bundle. - self._cache = lambda: None + # this is a little bit cursed, but it allows consumers to cache data + # that share the same lifetime as this input bundle. + self._cache = _Cache() def _normalize_path(self, path): raise NotImplementedError(f"not implemented! {self.__class__}._normalize_path()") diff --git a/vyper/utils.py b/vyper/utils.py index a7ca1bd441..165ae83921 100644 --- a/vyper/utils.py +++ b/vyper/utils.py @@ -2,7 +2,6 @@ import contextlib import decimal import enum -import functools import sys import time import traceback @@ -435,17 +434,13 @@ def indent(text: str, indent_chars: Union[str, List[str]] = " ", level: int = 1) return "".join(indented_lines) -def timeit(func): - @functools.wraps(func) - def timeit_wrapper(*args, **kwargs): - start_time = time.perf_counter() - result = func(*args, **kwargs) - end_time = time.perf_counter() - total_time = end_time - start_time - print(f"Function {func.__name__} Took {total_time:.4f} seconds") - return result - - return timeit_wrapper +@contextlib.contextmanager +def timeit(msg): + start_time = time.perf_counter() + yield + end_time = time.perf_counter() + total_time = end_time - start_time + print(f"{msg}: Took {total_time:.4f} seconds") @contextlib.contextmanager