diff --git a/CHANGELOG.md b/CHANGELOG.md index b52d7d01d..7103426dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed +- DEP: delete deprecated rocketpy.tools.cached_property [#587](https://github.com/RocketPy-Team/RocketPy/pull/587) - DOC: Improvements of Environment docstring phrasing [#565](https://github.com/RocketPy-Team/RocketPy/pull/565) - MNT: Refactor flight prints module [#579](https://github.com/RocketPy-Team/RocketPy/pull/579) - DOC: Convert CompareFlights example notebooks to .rst files [#576](https://github.com/RocketPy-Team/RocketPy/pull/576) diff --git a/rocketpy/environment/environment_analysis.py b/rocketpy/environment/environment_analysis.py index 0ed638091..da6fde364 100644 --- a/rocketpy/environment/environment_analysis.py +++ b/rocketpy/environment/environment_analysis.py @@ -3,6 +3,7 @@ import datetime import json from collections import defaultdict +from functools import cached_property import netCDF4 import numpy as np @@ -22,11 +23,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/mathutils/function.py b/rocketpy/mathutils/function.py index cefed044d..eda903bcc 100644 --- a/rocketpy/mathutils/function.py +++ b/rocketpy/mathutils/function.py @@ -7,6 +7,7 @@ import warnings from collections.abc import Iterable from copy import deepcopy +from functools import cached_property from inspect import signature from pathlib import Path @@ -14,11 +15,6 @@ import numpy as np from scipy import integrate, linalg, optimize -try: - from functools import cached_property -except ImportError: - from ..tools import cached_property - NUMERICAL_TYPES = (float, int, complex, np.ndarray, np.integer, np.floating) diff --git a/rocketpy/mathutils/vector_matrix.py b/rocketpy/mathutils/vector_matrix.py index 50d827659..332e1b680 100644 --- a/rocketpy/mathutils/vector_matrix.py +++ b/rocketpy/mathutils/vector_matrix.py @@ -1,8 +1,7 @@ from cmath import isclose +from functools import cached_property from itertools import product -from rocketpy.tools import cached_property - class Vector: """Pure python basic R3 vector class designed for simple operations. diff --git a/rocketpy/motors/hybrid_motor.py b/rocketpy/motors/hybrid_motor.py index 6f0849cd0..557333fe7 100644 --- a/rocketpy/motors/hybrid_motor.py +++ b/rocketpy/motors/hybrid_motor.py @@ -1,3 +1,5 @@ +from functools import cached_property + from rocketpy.tools import parallel_axis_theorem_from_com from ..mathutils.function import Function, funcify_method, reset_funcified_methods @@ -7,11 +9,6 @@ from .motor import Motor from .solid_motor import SolidMotor -try: - from functools import cached_property -except ImportError: - from ..tools import cached_property - class HybridMotor(Motor): """Class to specify characteristics and useful operations for Hybrid diff --git a/rocketpy/motors/liquid_motor.py b/rocketpy/motors/liquid_motor.py index 01f728473..7314e11ba 100644 --- a/rocketpy/motors/liquid_motor.py +++ b/rocketpy/motors/liquid_motor.py @@ -1,4 +1,4 @@ -import warnings +from functools import cached_property import numpy as np @@ -13,11 +13,6 @@ from ..prints.liquid_motor_prints import _LiquidMotorPrints from .motor import Motor -try: - from functools import cached_property -except ImportError: - from ..tools import cached_property - class LiquidMotor(Motor): """Class to specify characteristics and useful operations for Liquid diff --git a/rocketpy/motors/motor.py b/rocketpy/motors/motor.py index 3834f4a15..9429da88e 100644 --- a/rocketpy/motors/motor.py +++ b/rocketpy/motors/motor.py @@ -1,6 +1,7 @@ import re import warnings from abc import ABC, abstractmethod +from functools import cached_property import numpy as np @@ -9,11 +10,6 @@ from ..prints.motor_prints import _MotorPrints from ..tools import parallel_axis_theorem_from_com, tuple_handler -try: - from functools import cached_property -except ImportError: - from ..tools import cached_property - class Motor(ABC): """Abstract class to specify characteristics and useful operations for diff --git a/rocketpy/motors/solid_motor.py b/rocketpy/motors/solid_motor.py index 8b1c2362e..db3527a95 100644 --- a/rocketpy/motors/solid_motor.py +++ b/rocketpy/motors/solid_motor.py @@ -1,3 +1,5 @@ +from functools import cached_property + import numpy as np from scipy import integrate @@ -6,11 +8,6 @@ from ..prints.solid_motor_prints import _SolidMotorPrints from .motor import Motor -try: - from functools import cached_property -except ImportError: - from ..tools import cached_property - class SolidMotor(Motor): """Class to specify characteristics and useful operations for solid motors. diff --git a/rocketpy/motors/tank_geometry.py b/rocketpy/motors/tank_geometry.py index f1940cbea..2eb7bd27e 100644 --- a/rocketpy/motors/tank_geometry.py +++ b/rocketpy/motors/tank_geometry.py @@ -11,10 +11,7 @@ cache = lru_cache(maxsize=None) -try: - from functools import cached_property -except ImportError: - from ..tools import cached_property +from functools import cached_property class TankGeometry: diff --git a/rocketpy/plots/flight_plots.py b/rocketpy/plots/flight_plots.py index 4ae5141c9..21266a1f3 100644 --- a/rocketpy/plots/flight_plots.py +++ b/rocketpy/plots/flight_plots.py @@ -1,11 +1,8 @@ +from functools import cached_property + import matplotlib.pyplot as plt import numpy as np -try: - from functools import cached_property -except ImportError: - from ..tools import cached_property - class _FlightPlots: """Class that holds plot methods for Flight class. diff --git a/rocketpy/rocket/aero_surface.py b/rocketpy/rocket/aero_surface.py index c5d154f3e..d41240ac9 100644 --- a/rocketpy/rocket/aero_surface.py +++ b/rocketpy/rocket/aero_surface.py @@ -1,6 +1,5 @@ import warnings from abc import ABC, abstractmethod -from functools import cached_property import numpy as np from scipy.optimize import fsolve diff --git a/rocketpy/tools.py b/rocketpy/tools.py index cb3094343..acd0f4c27 100644 --- a/rocketpy/tools.py +++ b/rocketpy/tools.py @@ -8,36 +8,10 @@ from cftime import num2pydate from packaging import version as packaging_version -_NOT_FOUND = object() - # Mapping of module name and the name of the package that should be installed 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,