Type safety improvements using ty#1373
Merged
amilcarlucas merged 1 commit intomasterfrom Mar 12, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
tyconfiguration 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: ignoresuppressions. - Adjusted tests to satisfy
tytype 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
assertstatements 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., assignop_start = self.op_startand handle theNonecase with a clear error/return) so behavior is consistent regardless of optimization flags. This applies to the other similarassert ... is not Noneadditions in this file as well.
#!/usr/bin/env python3
You can also share your feedback on Copilot code review. Take the survey.
ardupilot_methodic_configurator/frontend_tkinter_component_editor.py
Outdated
Show resolved
Hide resolved
ardupilot_methodic_configurator/frontend_tkinter_pair_tuple_combobox.py
Outdated
Show resolved
Hide resolved
Contributor
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified FilesNo covered modified files...
|
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.