libtmux
libtmux copied to clipboard
snapshot(refactor[typing]): Improve type overrides with generics
#587
why: Remove the need for type: ignore comments on property overrides
what:
- Use Generic base classes with covariant type parameters
- Add properly typed overrides for inherited properties
- Define a clear SnapshotType union type for shared operations
- Improve type safety in filter_snapshot with better type checks
Summary by Sourcery
Improves type safety and reduces the need for type ignores by using generic base classes with covariant type parameters for snapshots. It also defines a union type for shared snapshot operations and improves type checking in the filter_snapshot function.
Enhancements:
- Improves type safety by using generic base classes with covariant type parameters.
- Defines a clear SnapshotType union type for shared operations.
- Improves type safety in filter_snapshot with better type checks by using isinstance.
- Adds properly typed overrides for inherited properties.
Reviewer's Guide by Sourcery
This pull request refactors the snapshot module to improve type safety by using generic base classes with covariant type parameters, defining a SnapshotType union, and adding properly typed overrides for inherited properties. This removes the need for type: ignore comments and enhances the overall type checking within the module, especially in functions like filter_snapshot.
No diagrams generated as the changes look simple and do not need a visual representation.
File-Level Changes
| Change | Details | Files |
|---|---|---|
Introduces generic base classes for _SealableWindowBase, _SealableSessionBase, and _SealableServerBase to improve type safety and remove the need for type: ignore comments on property overrides. |
|
src/libtmux/snapshot.py |
Defines a SnapshotType union type for shared operations across different snapshot classes. |
|
src/libtmux/snapshot.py |
Improves type safety in the filter_snapshot function by using the SnapshotType union and more specific type checks. |
|
src/libtmux/snapshot.py |
Updates the snapshot_to_dict function to use the SnapshotType union. |
|
src/libtmux/snapshot.py |
Updates the is_active inner function within snapshot_active_only to use the SnapshotType union. |
|
src/libtmux/snapshot.py |
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review! - Generate a plan of action for an issue: Comment
@sourcery-ai planon an issue to generate a plan of action for it.
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
Codecov Report
Attention: Patch coverage is 77.31481% with 147 lines in your changes missing coverage. Please review.
Project coverage is 79.23%. Comparing base (
5803841) to head (ac85da4). Report is 26 commits behind head on snapshots.
Additional details and impacted files
@@ Coverage Diff @@
## snapshots #590 +/- ##
=============================================
- Coverage 79.83% 79.23% -0.60%
=============================================
Files 22 33 +11
Lines 1914 2562 +648
Branches 294 416 +122
=============================================
+ Hits 1528 2030 +502
- Misses 266 375 +109
- Partials 120 157 +37
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.