Skip to content

typing: improve type safety in utils.py, application.py and models.py.#2486

Open
ExeWall wants to merge 5 commits intoborgbase:masterfrom
ExeWall:master
Open

typing: improve type safety in utils.py, application.py and models.py.#2486
ExeWall wants to merge 5 commits intoborgbase:masterfrom
ExeWall:master

Conversation

@ExeWall
Copy link
Copy Markdown

@ExeWall ExeWall commented Mar 29, 2026

Description

This pull request introduces type annotations and strengthens type safety across three core modules of the Vorta codebase to improve maintainability and prevent runtime errors.

Changes in detail:

  • src/vorta/utils.py: Added type hints to the search function and FilePathInfoAsync class. Improved logic to handle optional callables correctly.
  • src/vorta/application.py: Resolved NoneType vulnerabilities by adding defensive checks (type narrowing) before path operations and .as_uri() calls.
  • src/vorta/store/models.py: Fixed an incompatible type assignment between SQLAlchemy StringExpression and standard str by explicitly casting the pattern to a string.

Related Issue

This is a proactive improvement to address static analysis warnings and align with the project's move toward gradual typing. It also serves as my initial contribution for the GSoC 2026 application.

Motivation and Context

The main goal is to improve code robustness. By resolving these Mypy-reported issues, we prevent potential crashes (especially AttributeError on NoneType) that could occur if environment-dependent directories or database expressions are not handled safely.

How Has This Been Tested?

The changes were verified using Mypy 1.x in a local environment:

  • Ran mypy src/vorta/utils.py -> Success.
  • Ran mypy src/vorta/application.py -> Success.
  • Ran mypy src/vorta/store/models.py -> Success.
  • Environment: Python 3.10+ on Windows 11.
  • Regression: Verified that existing backup and search functionalities remain unaffected by the typing changes.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have read the CONTRIBUTING guide.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

I provide my contribution under the terms of the license of this repository and I affirm the Developer Certificate of Origin.

@ExeWall ExeWall changed the title typing: improve type safety in utils.py and application.py. typing: improve type safety in utils.py, application.py and models.py. Mar 30, 2026
@ExeWall
Copy link
Copy Markdown
Author

ExeWall commented Mar 30, 2026

@m3nu can you review when you have time? Thank you so much.

@ExeWall
Copy link
Copy Markdown
Author

ExeWall commented Apr 2, 2026

@m3nu, hiii, can you review when you have time? Thank you so much.

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.

1 participant