Skip to content

Fix type hinting for the Python module #1287

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

bcoconni
Copy link
Member

@bcoconni bcoconni commented May 24, 2025

The type hinting introduced by PR #755 is broken. By inspection of the stub files *.pyi it appears that the utility tool stubgen from the mypy package is producing garbage for modules generated by Cython .

This PR replaces the usage of stubgen by a new Python script pyxstubgen.py that parses jsbsim.pyx to find all the classes, methods and functions declarations with their type hints and then generates a proper stub file _jsbsim.pyi.

Since parsing a Cython file is no trivial job, the script pystubgen.py is using the lark parser (a parser toolkit fully written in Python). A grammar file cython.lark has been created for that purpose. It is the minimum grammar that works for the JSBSim cython code and is by no means pretending to be able to read any cython file.

This PR is addressing some proverbial itch scratching: I am annoyed that my favorite IDE does not autocomplete the classes and functions from the JSBSim Python module. I have run some tests that confirm that autocomplete works when the Python module is generated using the new script pyxstubgen.py.

Please note that this feature is meant to be used by our CI workflow when building the packages that will uploaded to PyPI. It is not part of the standard development cycle (i.e. write code/build/tests) so developers do not need to install lark on their systems.

@bcoconni bcoconni changed the title Fix the type hinting for the Python module Fix type hinting for the Python module May 24, 2025
Copy link

codecov bot commented May 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 24.76%. Comparing base (024046d) to head (01f067d).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1287   +/-   ##
=======================================
  Coverage   24.76%   24.76%           
=======================================
  Files         169      169           
  Lines       19598    19598           
=======================================
  Hits         4854     4854           
  Misses      14744    14744           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant