Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Get Instance Attributes #477

Merged
merged 7 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
25 changes: 23 additions & 2 deletions rocketpy/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2365,7 +2365,7 @@
self.wind_vs = wind_vs
self.levels = levels
self.temperatures = temperatures
self.time_array = time_array
self.time_array = time_array[:].tolist()
Gui-FernandesBR marked this conversation as resolved.
Show resolved Hide resolved
self.height = height

# Close weather data
Expand Down Expand Up @@ -2735,7 +2735,7 @@
self.wind_vs = wind_vs
self.levels = levels
self.temperatures = temperatures
self.time_array = time_array
self.time_array = time_array[:].tolist()

Check warning on line 2738 in rocketpy/environment/environment.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/environment/environment.py#L2738

Added line #L2738 was not covered by tests
self.height = height

# Close weather data
Expand Down Expand Up @@ -3126,7 +3126,18 @@
------
plot_info : Dict
Dict of data relevant to plot externally

Warning
-------
Deprecated in favor of `utilities.get_instance_attributes`.

"""
warnings.warn(
"The method 'all_plot_info_returned' is deprecated. "
MateusStano marked this conversation as resolved.
Show resolved Hide resolved
+ "Use 'utilities.get_instance_attributes' instead.",
DeprecationWarning,
)

grid = np.linspace(self.elevation, self.max_expected_height)
plot_info = dict(
grid=[i for i in grid],
Expand Down Expand Up @@ -3187,7 +3198,17 @@
------
info : Dict
Information relevant about the Environment class.

Warning
-------
Deprecated in favor of `utilities.get_instance_attributes`.

"""
warnings.warn(
"The method 'all_info_returned' is deprecated. "
+ "Use 'utilities.get_instance_attributes' instead.",
DeprecationWarning,
)

# Dictionary creation, if not commented follows the SI
info = dict(
Expand Down
23 changes: 23 additions & 0 deletions rocketpy/utilities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
import traceback
import warnings

Expand Down Expand Up @@ -654,3 +655,25 @@
if plot:
retfunc.plot(min_mass, max_mass, points)
return retfunc


def get_instance_attributes(instance):
Gui-FernandesBR marked this conversation as resolved.
Show resolved Hide resolved
"""Returns a dictionary with all attributes of a given instance.

Parameters
----------
instance : object
Instance of a class.

Returns
-------
Gui-FernandesBR marked this conversation as resolved.
Show resolved Hide resolved
dictionary
Dictionary with all attributes of the given instance.
"""
attributes_dict = dict()
members = inspect.getmembers(instance)
for member in members:

Check warning on line 675 in rocketpy/utilities.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/utilities.py#L673-L675

Added lines #L673 - L675 were not covered by tests
# Filter out methods and protected attributes
if not inspect.ismethod(member[1]) and not member[0].startswith("__"):
phmbressan marked this conversation as resolved.
Show resolved Hide resolved
attributes_dict[member[0]] = member[1]
return attributes_dict

Check warning on line 679 in rocketpy/utilities.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/utilities.py#L677-L679

Added lines #L677 - L679 were not covered by tests
Loading