Skip to content

Commit c31c6f8

Browse files
Merge pull request #587 from RocketPy-Team/mnt/delete-cached-property
DEP: delete deprecated rocketpy.tools.cached_property
2 parents a011c5a + 684b997 commit c31c6f8

File tree

12 files changed

+13
-69
lines changed

12 files changed

+13
-69
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3737

3838
### Changed
3939

40+
- DEP: delete deprecated rocketpy.tools.cached_property [#587](https://github.com/RocketPy-Team/RocketPy/pull/587)
4041
- DOC: Improvements of Environment docstring phrasing [#565](https://github.com/RocketPy-Team/RocketPy/pull/565)
4142
- MNT: Refactor flight prints module [#579](https://github.com/RocketPy-Team/RocketPy/pull/579)
4243
- DOC: Convert CompareFlights example notebooks to .rst files [#576](https://github.com/RocketPy-Team/RocketPy/pull/576)

rocketpy/environment/environment_analysis.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import datetime
44
import json
55
from collections import defaultdict
6+
from functools import cached_property
67

78
import netCDF4
89
import numpy as np
@@ -22,11 +23,6 @@
2223
from ..units import convert_units
2324
from .environment import Environment
2425

25-
try:
26-
from functools import cached_property
27-
except ImportError:
28-
from ..tools import cached_property
29-
3026
# TODO: the average_wind_speed_profile_by_hour and similar methods could be more abstract than currently are
3127

3228

rocketpy/mathutils/function.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@
77
import warnings
88
from collections.abc import Iterable
99
from copy import deepcopy
10+
from functools import cached_property
1011
from inspect import signature
1112
from pathlib import Path
1213

1314
import matplotlib.pyplot as plt
1415
import numpy as np
1516
from scipy import integrate, linalg, optimize
1617

17-
try:
18-
from functools import cached_property
19-
except ImportError:
20-
from ..tools import cached_property
21-
2218
NUMERICAL_TYPES = (float, int, complex, np.ndarray, np.integer, np.floating)
2319

2420

rocketpy/mathutils/vector_matrix.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from cmath import isclose
2+
from functools import cached_property
23
from itertools import product
34

4-
from rocketpy.tools import cached_property
5-
65

76
class Vector:
87
"""Pure python basic R3 vector class designed for simple operations.

rocketpy/motors/hybrid_motor.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from functools import cached_property
2+
13
from rocketpy.tools import parallel_axis_theorem_from_com
24

35
from ..mathutils.function import Function, funcify_method, reset_funcified_methods
@@ -7,11 +9,6 @@
79
from .motor import Motor
810
from .solid_motor import SolidMotor
911

10-
try:
11-
from functools import cached_property
12-
except ImportError:
13-
from ..tools import cached_property
14-
1512

1613
class HybridMotor(Motor):
1714
"""Class to specify characteristics and useful operations for Hybrid

rocketpy/motors/liquid_motor.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import warnings
1+
from functools import cached_property
22

33
import numpy as np
44

@@ -13,11 +13,6 @@
1313
from ..prints.liquid_motor_prints import _LiquidMotorPrints
1414
from .motor import Motor
1515

16-
try:
17-
from functools import cached_property
18-
except ImportError:
19-
from ..tools import cached_property
20-
2116

2217
class LiquidMotor(Motor):
2318
"""Class to specify characteristics and useful operations for Liquid

rocketpy/motors/motor.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
import warnings
33
from abc import ABC, abstractmethod
4+
from functools import cached_property
45

56
import numpy as np
67

@@ -9,11 +10,6 @@
910
from ..prints.motor_prints import _MotorPrints
1011
from ..tools import parallel_axis_theorem_from_com, tuple_handler
1112

12-
try:
13-
from functools import cached_property
14-
except ImportError:
15-
from ..tools import cached_property
16-
1713

1814
class Motor(ABC):
1915
"""Abstract class to specify characteristics and useful operations for

rocketpy/motors/solid_motor.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from functools import cached_property
2+
13
import numpy as np
24
from scipy import integrate
35

@@ -6,11 +8,6 @@
68
from ..prints.solid_motor_prints import _SolidMotorPrints
79
from .motor import Motor
810

9-
try:
10-
from functools import cached_property
11-
except ImportError:
12-
from ..tools import cached_property
13-
1411

1512
class SolidMotor(Motor):
1613
"""Class to specify characteristics and useful operations for solid motors.

rocketpy/motors/tank_geometry.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111

1212
cache = lru_cache(maxsize=None)
1313

14-
try:
15-
from functools import cached_property
16-
except ImportError:
17-
from ..tools import cached_property
14+
from functools import cached_property
1815

1916

2017
class TankGeometry:

rocketpy/plots/flight_plots.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1+
from functools import cached_property
2+
13
import matplotlib.pyplot as plt
24
import numpy as np
35

4-
try:
5-
from functools import cached_property
6-
except ImportError:
7-
from ..tools import cached_property
8-
96

107
class _FlightPlots:
118
"""Class that holds plot methods for Flight class.

rocketpy/rocket/aero_surface.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import warnings
22
from abc import ABC, abstractmethod
3-
from functools import cached_property
43

54
import numpy as np
65
from scipy.optimize import fsolve

rocketpy/tools.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,10 @@
88
from cftime import num2pydate
99
from packaging import version as packaging_version
1010

11-
_NOT_FOUND = object()
12-
1311
# Mapping of module name and the name of the package that should be installed
1412
INSTALL_MAPPING = {"IPython": "ipython"}
1513

1614

17-
class cached_property:
18-
def __init__(self, func):
19-
self.func = func
20-
self.attrname = None
21-
self.__doc__ = func.__doc__
22-
23-
def __set_name__(self, owner, name):
24-
self.attrname = name
25-
26-
def __get__(self, instance, owner=None):
27-
if instance is None:
28-
return self
29-
if self.attrname is None:
30-
raise TypeError(
31-
"Cannot use cached_property instance without calling __set_name__ on it."
32-
)
33-
cache = instance.__dict__
34-
val = cache.get(self.attrname, _NOT_FOUND)
35-
if val is _NOT_FOUND:
36-
val = self.func(instance)
37-
cache[self.attrname] = val
38-
return val
39-
40-
4115
def tuple_handler(value):
4216
"""Transforms the input value into a tuple that
4317
represents a range. If the input is an input or float,

0 commit comments

Comments
 (0)