diff --git a/redbot/core/__init__.py b/redbot/core/__init__.py index ddebbea15..a755816f7 100644 --- a/redbot/core/__init__.py +++ b/redbot/core/__init__.py @@ -2,7 +2,6 @@ import discord as _discord from .. import __version__, version_info, VersionInfo from .config import Config -from .utils.safety import warn_unsafe as _warn_unsafe __all__ = ["Config", "__version__", "version_info", "VersionInfo"] diff --git a/redbot/core/utils/caching.py b/redbot/core/utils/caching.py deleted file mode 100644 index 1057e3759..000000000 --- a/redbot/core/utils/caching.py +++ /dev/null @@ -1,53 +0,0 @@ -import collections - - -class LRUDict: - """ - dict with LRU-eviction and max-size - - This is intended for caching, it may not behave how you want otherwise - - This uses collections.OrderedDict under the hood, but does not directly expose - all of it's methods (intentional) - """ - - def __init__(self, *keyval_pairs, size): - self.size = size - self._dict = collections.OrderedDict(*keyval_pairs) - - def __contains__(self, key): - if key in self._dict: - self._dict.move_to_end(key, last=True) - return True - return False - - def __getitem__(self, key): - ret = self._dict.__getitem__(key) - self._dict.move_to_end(key, last=True) - return ret - - def __setitem__(self, key, value): - if key in self._dict: - self._dict.move_to_end(key, last=True) - self._dict[key] = value - if len(self._dict) > self.size: - self._dict.popitem(last=False) - - def __delitem__(self, key): - return self._dict.__delitem__(key) - - def clear(self): - return self._dict.clear() - - def pop(self, key): - return self._dict.pop(key) - - # all of the below access all of the items, and therefore shouldn't modify the ordering for eviction - def keys(self): - return self._dict.keys() - - def items(self): - return self._dict.items() - - def values(self): - return self._dict.values() diff --git a/redbot/core/utils/safety.py b/redbot/core/utils/safety.py deleted file mode 100644 index 9ceaf894b..000000000 --- a/redbot/core/utils/safety.py +++ /dev/null @@ -1,49 +0,0 @@ -import warnings -import functools - - -def unsafe(f, message=None): - """ - Decorator form for marking a function as unsafe. - - This form may not get used much, but there are a few cases - we may want to add something unsafe generally, but safe in specific uses. - - The warning can be suppressed in the safe context with warnings.catch_warnings - This should be used sparingly at most. - """ - - def wrapper(func): - @functools.wraps(func) - def get_wrapped(*args, **kwargs): - actual_message = message or f"{func.__name__} is unsafe for use" - warnings.warn(actual_message, stacklevel=3, category=RuntimeWarning) - return func(*args, **kwargs) - - return get_wrapped - - return wrapper - - -def warn_unsafe(f, message=None): - """ - Function to mark function from dependencies as unsafe for use. - - Warning: There is no check that a function has already been modified. - This form should only be used in init, if you want to mark an internal function - as unsafe, use the decorator form above. - - The warning can be suppressed in safe contexts with warnings.catch_warnings - This should be used sparingly at most. - """ - - def wrapper(func): - @functools.wraps(func) - def get_wrapped(*args, **kwargs): - actual_message = message or f"{func.__name__} is unsafe for use" - warnings.warn(actual_message, stacklevel=3, category=RuntimeWarning) - return func(*args, **kwargs) - - return get_wrapped - - return wrapper(f)