Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions rocketpy/environment/environment_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import numpy as np
import pytz

try:
from functools import cached_property
except ImportError:
from ..tools import cached_property
Comment on lines +11 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually deleted the try-except statement and simply import using from functools import cached_property. This will work fine in any environment with python>3.8, so we are covered.

Also, there are a few more files where we do this kind of try-except.

image


from ..mathutils.function import Function
from ..plots.environment_analysis_plots import _EnvironmentAnalysisPlots
from ..prints.environment_analysis_prints import _EnvironmentAnalysisPrints
Expand All @@ -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


Expand Down
25 changes: 1 addition & 24 deletions rocketpy/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,14 @@
import pytz
from cftime import num2pydate
from packaging import version as packaging_version
from functools import cached_property

_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,
Expand Down