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

BUG: Fix minor type hinting problems #598

Merged
merged 1 commit into from
May 13, 2024

Conversation

nalquas
Copy link
Contributor

@nalquas nalquas commented May 10, 2024

Pull request type

  • Code changes (bugfix, features)

Checklist

  • Lint (black rocketpy/ tests/) has passed locally
  • All tests (pytest tests -m slow --runslow) have passed locally
  • CHANGELOG.md has been updated (if relevant)

Current behavior

Assume basic type checking is active in VSCode. If you try to assign a float to one of the following function parameters, you get a warning that float is not compatible with int:

  • Environment constructor: latitude, longitude, elevation
  • SolidMotor constructor: nozzle_position
  • Rocket.add_trapezoidal_fins: cant_angle
  • Flight constructor: inclination, heading

The reason for the warning seems to be that the default values for those parameters is an integer, so the type checker assumes only ints are supported.

New behavior

No warning is given when a float is assigned to the listed parameters. Furthermore, no warning is given when assigning an int (just like before), because casting an int to a float does not warrant a warning for the type checker.

Breaking change

  • No

Additional information

When not using type hinting, the changes should not have any effect, as I have only added a ".0" to the end of the affected ints.

The docs/comments in the code even say that the mentioned parameters support float, but the type checker in VSCode didn't care 😅.

There are likely many more such cases; this PR only covers parameters that I came across so far (so I don't have to see those warnings in the project I work on). A proper solution would be to actually add type hints to everything in the repository.

I am aware of #444, where it was decided that type hinting will not be actively supported in this repository due to too much development overhead.

@nalquas nalquas requested a review from a team as a code owner May 10, 2024 14:24
@Gui-FernandesBR Gui-FernandesBR added this to the Release v1.X.0 milestone May 13, 2024
Copy link
Member

@Gui-FernandesBR Gui-FernandesBR left a comment

Choose a reason for hiding this comment

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

LGTM,

Thank you for your contribution, @nalquas !

I hope one day we give a second change to the idea of using type hinting in this RocketPy repo, this could help us during the development phases. But I understand that is complicated to maintain.

@Gui-FernandesBR Gui-FernandesBR merged commit 693ffac into RocketPy-Team:develop May 13, 2024
7 of 8 checks passed
@nalquas nalquas deleted the bug/minor-type-hints branch May 13, 2024 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

2 participants