diff --git a/rocketpy/environment/environment_analysis.py b/rocketpy/environment/environment_analysis.py index 2be707d73..07ae8e5ca 100644 --- a/rocketpy/environment/environment_analysis.py +++ b/rocketpy/environment/environment_analysis.py @@ -8,6 +8,11 @@ import numpy as np import pytz +try: + from functools import cached_property +except ImportError: + from ..tools import cached_property + from ..mathutils.function import Function from ..plots.environment_analysis_plots import _EnvironmentAnalysisPlots from ..prints.environment_analysis_prints import _EnvironmentAnalysisPrints @@ -22,11 +27,6 @@ from ..units import convert_units from .environment import Environment -try: - from functools import cached_property -except ImportError: - from ..tools import cached_property - # TODO: the average_wind_speed_profile_by_hour and similar methods could be more abstract than currently are diff --git a/rocketpy/tools.py b/rocketpy/tools.py index 6e765ca7a..89de666be 100644 --- a/rocketpy/tools.py +++ b/rocketpy/tools.py @@ -6,6 +6,7 @@ import pytz from cftime import num2pydate from packaging import version as packaging_version +from functools import cached_property _NOT_FOUND = object() @@ -13,30 +14,6 @@ INSTALL_MAPPING = {"IPython": "ipython"} -class cached_property: - def __init__(self, func): - self.func = func - self.attrname = None - self.__doc__ = func.__doc__ - - def __set_name__(self, owner, name): - self.attrname = name - - def __get__(self, instance, owner=None): - if instance is None: - return self - if self.attrname is None: - raise TypeError( - "Cannot use cached_property instance without calling __set_name__ on it." - ) - cache = instance.__dict__ - val = cache.get(self.attrname, _NOT_FOUND) - if val is _NOT_FOUND: - val = self.func(instance) - cache[self.attrname] = val - return val - - def tuple_handler(value): """Transforms the input value into a tuple that represents a range. If the input is an input or float,