-
-
Notifications
You must be signed in to change notification settings - Fork 237
MNT: deprecated decorator #830
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
Conversation
phmbressan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very interesting implementation.
I know that Python 3.13 added a similar decorator. I don't think it has the same custom functionalities (such as providing an alternative). Nonetheless, it is worth the read.
Since this Python is far from being RocketPy minimum required version, even if we were to use it, a custom version would be needed to support other Python versions (similarly to what happed with cached_property a few years ago). Therefore, I agree with this PR implementation.
Optionally, we could discuss the possibility of changing the parameters so that it is compatible with the Python standard one when/if we were to change to it in the future. Another idea for discussion is having the Python default one if the user has a >= 3.13 Python version.
8e2824a to
cb62905
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
A pull request introducing a reusable deprecated decorator and replacing inline deprecation warnings with that decorator for legacy methods.
- Added a
deprecateddecorator inrocketpy/tools.pyto standardize deprecation notices. - Removed manual
warnings.warn(...)calls fromRocket.add_finsandFunction.plot1D/plot2D, replacing them with the new decorator. - Updated imports in affected modules to include the
deprecateddecorator.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| rocketpy/tools.py | Added warnings import and defined the deprecated decorator. |
| rocketpy/rocket/rocket.py | Imported deprecated; applied decorator to add_fins and removed manual warning. |
| rocketpy/mathutils/function.py | Imported deprecated; applied decorator to plot1D/plot2D and removed manual warnings. |
Comments suppressed due to low confidence (2)
rocketpy/tools.py:32
- Consider adding unit tests for the new
deprecateddecorator to verify that it emits the correct warnings and preserves function metadata.
def deprecated(reason=None, version=None, alternative=None):
rocketpy/tools.py:68
- The decorator uses
functools.wrapsbutfunctoolsis not imported. Addimport functoolsat the top of the file.
@functools.wraps(func)
I agree - it's great that Python 3.13 introduces a standard deprecation decorator, but as you mentioned, our minimum supported version is still far from that, so a custom solution makes sense for now. I also appreciate your point about aligning our decorator’s parameters with the standard one for easier transition in the future; that sounds like a good idea and would make any future migration smoother. Regarding feature-detection for Python ≥3.13, we could look into conditionally using the standard decorator when available, and fall back to our custom one otherwise. However, I believe the benefits from that would not be significant. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #830 +/- ##
===========================================
+ Coverage 79.11% 80.02% +0.90%
===========================================
Files 96 98 +2
Lines 11575 12003 +428
===========================================
+ Hits 9158 9605 +447
+ Misses 2417 2398 -19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
* ENH: refactor motor prints classes to inherit from _MotorPrints * STY: make format * MNT: update code and remove deprecated functions * ENH: add deprecation decorator and update deprecated methods * make format * fix warnings
* DRAFT: for ENH/3-dof-simulation (See #655) ENH: adds 3 DOF simulation capability to rocketpy.Flight. *ENH: added "u_dot_3dof" for "solid_propulsion" mode *ENH: adding "u_dot_generalized_3dof" for "standard" mode (still incomplete) *ENH: new parameter "simulation_mode" for swtiching between 3 dof and 6 dof *ENH: updated conditions for "__init_equations_of_motion" *ENH: 2 new example files have been created to test 3 dof model "test_bella_lui_flight_sim" and "test_camoes_flight_sim" * ENH/3-dof-simulation (See RocketPy-Team#655) ENH: adds 3 DOF simulation capability to rocketpy.Flight. *ENH: added "u_dot_3dof" for "solid_propulsion" mode *ENH: added "u_dot_generalized_3dof" for "standard" mode *ENH: new parameter "simulation_mode" for swtiching between 3 dof and 6 dof *ENH: updated conditions for "__init_equations_of_motion" * MNT: cleaned up new functions and ENH: fixed standard 3 dof *MNT: Cleaned up the "u_dot_3dof" and "u_dot_generalized_3_dof" *MNT: Corrected Typos in "simulation_mode" description *ENH: "u_dot_generalized_3_dof" fixed and tested on examples. * ENH: Addition of point mass classes to rocketpy.rocket and rocketpy.motor ENH: added "BaseRocket" and "PointMassRocket" to rocket class ENH: added "PointMassMotor" to motor class with various input cases of thrust values * ENH: PointMassMotor and PointMassRocket working as intended after some tests ENH: Added a new jupyter notebook for a simplified 3 DOF example MNT: PointMassMotor intialization error fixed MNT: PointMassRocket properties enhanced based on the example runs * MNT: Removing unnecessary files added by mistake. * MNT: Cleaned up PointMassMotor and PointMassRocket class MNT: Cleaned up the flight class u_dot_generalized_3dof TODO: Add info for 3 dof cases and fix some new issues when parachute is added. * MNT: Cleaning up flight class and PointMassMotor class * MNT: point mass motor cleanup -MNT: removing the parameters not needed for point mass kind of motors -MNT: removing extra parameter thrust_curve -MNT: fixing problems with motor class inheritance * ENH: restructuring rocket class -ENH: removed 'BaseRocket' class now 'PointMassRocket' inherits directly from 'Rocket' class * MNT: fixing certain calculations on point mass motor -MNT: fixed calculations of mass flow rate and exhaust velocity -MNT: adjusted propellant initial mass setter error by allocating the input initial mass to the property * Rename PointMassMotor.py to pointmassmotor.py MNT: renaming pointmassmotor.py -MNT:snake case renaming * MNT: updates to 3dof example -MNT: incorporating latest structural changes made to PointMassMotor and PointMassRocket * MNT: lint cleanup and adding 3dof to init -MNT: cleaned up PointMassRocket rocket.py for linters. -ENH: including PointMassMotor in motors and rocketpy __init__.py -MNT: adopting to structural changes in 3dof on the 3_DOF_TRIAL.ipynb -MNT: including pointmassmotor in settings.json as a spell word * MNT: Point mass motor and rocket fixes - MNT: pointmassmotor fixing the various properties. - MNT: fixing super init and init inheritance by changing order in pointmassrocket - MNT: pointmassrocket property setter and default value fixes * MNT: flight class fix on simulation mode detection - MNT: implemented identification of simulation mode based on check if point mass objects are used * MNT: make format changes - MNT: used make format to correct formatting mistakes on all the new classes. * MNT: point mass motor cleanup -MNT: removing the parameters not needed for point mass kind of motors -MNT: removing extra parameter thrust_curve -MNT: fixing problems with motor class inheritance * ENH: restructuring rocket class -ENH: removed 'BaseRocket' class now 'PointMassRocket' inherits directly from 'Rocket' class * MNT: fixing certain calculations on point mass motor -MNT: fixed calculations of mass flow rate and exhaust velocity -MNT: adjusted propellant initial mass setter error by allocating the input initial mass to the property * Rename PointMassMotor.py to pointmassmotor.py MNT: renaming pointmassmotor.py -MNT:snake case renaming * ENH: _MotorPrints inheritance - issue #460 (#828) * ENH: refactor motor prints classes to inherit from _MotorPrints * STY: make format * ENH: add entry for _MotorPrints inheritance in changelog * MNT: fix deprecations and warnings (#829) * MNT: update code and remove deprecated functions * MNT: simplify geodesic_to_utm import and usage in Environment class * MNT: update CHANGELOG to fix deprecations and warnings * make lint * MNT: remove unused post_processed attribute from Flight class * MNT: update matplotlib version to 3.8.3 in requirements.txt * MNT: update matplotlib version to 3.10.0 in requirements.txt * MNT: downgrade matplotlib version to 3.9.0 in requirements.txt * MNT: change boxplot orientation to horizontal for compatibility with future Python versions * MNT: change boxplot orientation from horizontal to vertical for consistency * DEV: streamline caching of Python dependencies in GitHub Actions * ENH: Add the Coriolis Force to the Flight class (#799) * wind factor bug corrected the wind factor wasn't applied to the env.wind_velocity properties * BUG: StochasticModel visualize attributes of a uniform distribution It showed the nominal and the standard deviation values and it doesn't make sense in a uniform distribution. In a np.random.uniform the 'nominal value' is the lower bound of the distribution, and the 'standard deviation' value is the upper bound. Now, a new condition has been added for the uniform distributions where the mean and semi range are calculated and showed. This way the visualize_attribute function will show the whole range where the random values are uniformly taken in * variable names corrections * Corrections requested by the pylint test * ENH: add multiplication for 2D functions in rocketpy.function Added the ability to multiply functions with 2D domains in the __mul__ function * ENH: StochasticAirBrakes class created The StochasticAirBrakes class has been created. The __init__.py files in the stochastic and rocketpy folders have also been modified accordingly to incorporate this new class * ENH: set_air_brakes function created This functions appends an airbrake and controller objects previuosly created to the rocket * ENH: add StochasticAirBrake to rocketpy.stochastic_rocket Some functions has been modified and other has been created in order to include the new StochasticAirBrakes feature into the StochasticRocket class. A new function named 'add_air_brakes' has been created to append a StochasticAirBrakes and Controller objects to the StochasticRocket object. A new function '_create_air_brake' has been introduced to create a sample of an AirBrake object through a StochasticAirBrake object. Enventually, the 'create_object' function has been modified to add the sampled AirBrakes to the sampled Rocket * BUG: StochasticAirBrake object input in _Controller When defining the _Controller object a StochasticAirBrake was input. This is already corrected and a AirBrake object is now introduced * ENH: add time_overshoot option to rocketpy.stochastic_flight Since the new StochasticAirBrake class is defined, we need the 'time_overshoot' option in the Flight class to ensure that the time step defined in the simulation is the controller sampling rate. The MonteCarlo class has had to be modified as well to include this option. * DOC: StochasticAirBrakes related documentation added Documentation related to the StochasticAirBrakes implementation has been added in StochasticAirBrakes, StochasticRocket and Rocket classes. * ENH: pylint recommendations done * ENH: Reformatted files to pass Ruff linting checks * ENH: Update rocketpy/stochastic/stochastic_rocket.py Unnecessary comment Co-authored-by: Gui-FernandesBR <63590233+Gui-FernandesBR@users.noreply.github.com> * ENH: more intuitive uniform distribution display in StochasticModel Co-authored-by: MateusStano <69485049+MateusStano@users.noreply.github.com> * DOC: improve drag curve factor definition in StochasticAirBrakes * ENH: Change assert statement to if Co-authored-by: Gui-FernandesBR <63590233+Gui-FernandesBR@users.noreply.github.com> * DOC: better explanation of __mul__ function Co-authored-by: MateusStano <69485049+MateusStano@users.noreply.github.com> * ENH: delete set_air_brakes function for simplicity * ENH: inertial foreces added to u_dot_generalized * ENH: define Earth's angular velocity vector in Environment * ENH: some corrections to the Flight class * ENH: modifications in the Flight class * DOC: improving Environment documentation * DOC: more improvements in the Environment class * ENH: format changes done * DOC: env.earth_rotation_vector improved Co-authored-by: Gui-FernandesBR <63590233+Gui-FernandesBR@users.noreply.github.com> * ENH: Coriolis acceleration added to u_dot * BUG: print left * ENH: ruff changes * ENH: CHANGELOG updated * ENH: remove unecessary frame rotation * ENH: remove rotation from solid prop udot * ENH: add coriolis to parachute * TST: fix tests values * MNT: remove debug functions * DEV: changelog --------- Co-authored-by: Gui-FernandesBR <63590233+Gui-FernandesBR@users.noreply.github.com> Co-authored-by: MateusStano <69485049+MateusStano@users.noreply.github.com> Co-authored-by: MateusStano <go34lap@mytum.de> Co-authored-by: MateusStano <mateusstano@usp.br> * MNT: deprecated decorator (#830) * ENH: refactor motor prints classes to inherit from _MotorPrints * STY: make format * MNT: update code and remove deprecated functions * ENH: add deprecation decorator and update deprecated methods * make format * fix warnings * MNT: updates to 3dof example -MNT: incorporating latest structural changes made to PointMassMotor and PointMassRocket * MNT: lint cleanup and adding 3dof to init -MNT: cleaned up PointMassRocket rocket.py for linters. -ENH: including PointMassMotor in motors and rocketpy __init__.py -MNT: adopting to structural changes in 3dof on the 3_DOF_TRIAL.ipynb -MNT: including pointmassmotor in settings.json as a spell word * MNT: Point mass motor and rocket fixes - MNT: pointmassmotor fixing the various properties. - MNT: fixing super init and init inheritance by changing order in pointmassrocket - MNT: pointmassrocket property setter and default value fixes * MNT: flight class fix on simulation mode detection - MNT: implemented identification of simulation mode based on check if point mass objects are used * MNT: make format changes - MNT: used make format to correct formatting mistakes on all the new classes. * MNT: rocket.py removed pointmassrocket inertia - MNT: removed dry inertia setters from pointmassrocket * MNT: flight.py review updates - MNT: fixed the order of attributes shifted simulation mode after ode solver - MNT: added flight.simulation in docstring * MNT: flight.py sanitization - MNT: manually updated flight.py to match the current version on develop * MNT: make format and renaming 3 dof example - MNT: make format changes to flight.py - MNT: "3_DOF_TRIAL.ipynb" renamed to "3_dof_trial_sim.ipynb" * MNT: Update flight.py to remove duplicate line Co-authored-by: Gui-FernandesBR <63590233+Gui-FernandesBR@users.noreply.github.com> * MNT: correcting indentation in flight.py - MNT: indentation error in flight class for callback under parachute trigger * MNT: docstring for pointmassrocket in rocket.py - MNT: added a short doc string describing pointmassrocket class * MNT: removing property from rocket.py poitmassrocket - MNT: properties which are similar to attributes are not needed were removed from pointmassrocket - MNT: removing default set values for attributes for pointmassrocket * ENH: first version of tests for 3dof rocketpy - ENH: added first versions of tests using python assert statements for pointmassmotor, pointmassrocket and 3dof segments of flight. * adds docs * Refactor PointMassRocket class into its own module for improved organization and clarity * refactored tests * fix test * remove example notebook * type hint fix * Configure matplotlib to use non-interactive backend for tests * fix tests * solve comments by copilot * small fix * DOC: Update test docstrings to follow RocketPy NumPy style guidelines * docs: Update test docstrings to follow RocketPy style guidelines Co-authored-by: aZira371 <99824864+aZira371@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: aZira371 <99824864+aZira371@users.noreply.github.com> --------- Co-authored-by: Gui-FernandesBR <63590233+Gui-FernandesBR@users.noreply.github.com> Co-authored-by: Gui-FernandesBR <guilherme_fernandes@usp.br> Co-authored-by: Kevin Alcañiz <kevinalcaniz22@gmail.com> Co-authored-by: MateusStano <69485049+MateusStano@users.noreply.github.com> Co-authored-by: MateusStano <go34lap@mytum.de> Co-authored-by: MateusStano <mateusstano@usp.br> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Solves #669