Skip to content

Conversation

@multiplemonomials
Copy link
Collaborator

@multiplemonomials multiplemonomials commented Nov 28, 2025

Summary of changes

This PR adds some linting support for the Python scripts in Mbed. It might seem like a small thing, but I believe linters like Ruff and pyright are a great way to catch small mistakes before they become a problem (especially in a language like Python that lets you play it fast and loose with types). I don't really expect to catch bugs in the existing scripts, as those have been working for some time, but I really want to have the linter available when making my own changes and additions to these scripts down the road.

Note that for now I only added the linters to the newest python scripts, the mbed_tools and mbed_platformio packages. The old scripts are largely deprecated and don't have any type annotations, so I feel like linting those would be a significant uphill battle, and I'd want to prune out a lot of the unused ones first.

Impact of changes

  • All mbed_tools and mbed_platformio python code now passes linters
  • Removed a fair bit of old unused code in mbed_tools, like code that creates placeholder CMakeLists.txt files and code that downloads Mbed and its libraries from Git repos
  • Lots of common issues/quirks were resolved in the code, either fully automatically or manually based on what the linter flagged:
    • Functions that act as overrides but are missing the @override decorator now have it (and their arguments are made to match exactly with the base class function)
    • Exception messages now get saved into a variable before the exception is thrown to clean up the stacktrace
    • All imports are now sorted
    • All exception class names now end with -Error

Migration actions required

Documentation


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[X] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[X] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

@multiplemonomials multiplemonomials changed the title [draft] Add Ruff and Basedpyright linters to (the newer) Python scripts in Mbed Add Ruff and Basedpyright linters to (the newer) Python scripts in Mbed Nov 29, 2025
@multiplemonomials multiplemonomials self-assigned this Nov 29, 2025
@multiplemonomials multiplemonomials merged commit 8f48d0d into master Dec 2, 2025
50 checks passed
@multiplemonomials multiplemonomials deleted the dev/add-python-linters branch December 2, 2025 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants