Skip to content

Type safety improvements using ty#1373

Merged
amilcarlucas merged 1 commit intomasterfrom
ty_fixes
Mar 12, 2026
Merged

Type safety improvements using ty#1373
amilcarlucas merged 1 commit intomasterfrom
ty_fixes

Conversation

@amilcarlucas
Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings March 12, 2026 19:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Introduces configuration and code/test updates to adopt the ty type checker, aiming to reduce type-checker noise while tightening some annotations and protocol-based typing.

Changes:

  • Added ty configuration and helper scripts to inspect/type-check results.
  • Updated production code type hints (notably MAVLink connection typing and Tkinter plugin view typing) and removed several type: ignore suppressions.
  • Adjusted tests to satisfy ty type narrowing and ignore missing-argument constructor calls in patched fixtures.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
ty.toml Adds ty rule configuration (currently mostly set to ignore).
scripts/ty_check_counts.ps1 Adds a PowerShell helper to group ty check warnings/errors.
scripts/generate_codebase_pie_chart.py Adds a targeted ty ignore for tuple indexing.
tests/unit_backend_internet_download_resume.py Adds an assertion to narrow headers type.
tests/test_frontend_tkinter_component_editor_base.py Adds ty ignore for patched constructor call.
tests/test_frontend_tkinter_component_editor.py Adds ty ignore for patched constructor call.
tests/integration_frontend_tkinter_component_editor.py Adds ty ignore for patched constructor call.
tests/test_data_model_vehicle_components_common.py Replaces hasattr + cast with getattr + callable for post-init invocation.
tests/test_data_model_flightcontroller_info.py Fixes contextmanager return type annotation to Generator.
tests/test_backend_mavftp_aux.py Adds assertions used for ty narrowing.
tests/test_backend_mavftp.py Normalizes expected_message to str before assertion.
tests/gui_frontend_tkinter_parameter_editor.py Removes cast usage for Tkinter Toplevel references.
ardupilot_methodic_configurator/frontend_tkinter_parameter_editor.py Types plugin view as PluginView, removes attr-defined ignores, adds cast for plugin_view.
ardupilot_methodic_configurator/frontend_tkinter_pair_tuple_combobox.py Forces longest_value to str for font measurement.
ardupilot_methodic_configurator/frontend_tkinter_component_editor.py Introduces EntryWidget return type and _path parameter workaround.
ardupilot_methodic_configurator/backend_mavftp.py Adds a command() setter and several runtime asserts for type narrowing.
ardupilot_methodic_configurator/backend_flightcontroller_protocols.py Expands MavlinkConnection union types (TYPE_CHECKING-only).
ardupilot_methodic_configurator/backend_flightcontroller_params.py Replaces mavutil.mavlink_connection return annotation with MavlinkConnection.
ardupilot_methodic_configurator/backend_flightcontroller_files.py Replaces mavutil.mavlink_connection return annotation with MavlinkConnection.
ardupilot_methodic_configurator/backend_flightcontroller_factory_mavlink.py Uses MavlinkConnection typing and adds pyright ignore on return.
ardupilot_methodic_configurator/backend_flightcontroller_factory_mavftp.py Uses MavlinkConnection typing for factory arguments.
ardupilot_methodic_configurator/backend_flightcontroller_connection.py Replaces some union-attr ignores and returns Union[MavlinkConnection, None].
ardupilot_methodic_configurator/backend_flightcontroller_commands.py Replaces some union-attr ignores with pyright suppressions only.
ardupilot_methodic_configurator/backend_flightcontroller.py Removes union-attr ignore for reboot_autopilot() call.
Comments suppressed due to low confidence (1)

ardupilot_methodic_configurator/backend_mavftp.py:1

  • Using runtime assert statements purely for type narrowing ("to keep ty happy") is brittle because asserts can be stripped with Python -O, and they don’t provide a controlled fallback path. Prefer explicit control flow for narrowing (e.g., assign op_start = self.op_start and handle the None case with a clear error/return) so behavior is consistent regardless of optimization flags. This applies to the other similar assert ... is not None additions in this file as well.
#!/usr/bin/env python3

You can also share your feedback on Copilot code review. Take the survey.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 12, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
11695 10815 92% 89% 🟢

New Files

No new covered files...

Modified Files

No covered modified files...

updated for commit: c63ff71 by action🐍

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 12, 2026

Test Results

     4 files  ±0       4 suites  ±0   41m 15s ⏱️ -14s
 3 199 tests ±0   3 197 ✅ ±0   2 💤 ±0  0 ❌ ±0 
12 588 runs  ±0  12 569 ✅ +1  19 💤  - 1  0 ❌ ±0 

Results for commit c63ff71. ± Comparison against base commit 00ab02d.

♻️ This comment has been updated with latest results.

@amilcarlucas amilcarlucas merged commit 882eede into master Mar 12, 2026
31 checks passed
@amilcarlucas amilcarlucas deleted the ty_fixes branch March 12, 2026 21:10
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.

2 participants