Add comprehensive type annotations and mypy configuration with Python 3.10+ support#255
Add comprehensive type annotations and mypy configuration with Python 3.10+ support#255
Conversation
….py, entries.py Co-authored-by: pylipp <10617122+pylipp@users.noreply.github.com>
Co-authored-by: pylipp <10617122+pylipp@users.noreply.github.com>
Co-authored-by: pylipp <10617122+pylipp@users.noreply.github.com>
…ons, and README documentation Co-authored-by: pylipp <10617122+pylipp@users.noreply.github.com>
pylipp
left a comment
There was a problem hiding this comment.
couple of remarks, please work on these
| pip install -U -e .[develop] | ||
| pip install -U coveralls | ||
| - name: Run style-checks | ||
| uses: pre-commit/action@v3.0.1 |
There was a problem hiding this comment.
the pre-commit action fails in CI, please fix it. Don't explicitly add another step below to run mypy
There was a problem hiding this comment.
Fixed the pre-commit mypy configuration by adding pass_filenames: false to prevent mypy from receiving individual file arguments. Also removed the explicit mypy step from CI as requested. The pre-commit hooks now pass successfully. (3cc87c7)
|
|
||
| The mypy configuration in `pyproject.toml` uses a gradual typing approach: | ||
| - Basic type safety is enforced | ||
| - Some strict checks are disabled during the migration period |
There was a problem hiding this comment.
please explain to me in a PR comment how I should proceed with the migration
There was a problem hiding this comment.
Added a comprehensive migration guide to the README explaining how to progressively tighten the typing configuration:
- Enable stricter checks by uncommenting options in pyproject.toml
- Re-enable unused ignore warnings once annotations are complete
- Remove type: ignore comments as underlying issues are fixed
- Update to use more specific types instead of Any
The current configuration provides a solid foundation for gradual migration. (3cc87c7)
| "marshmallow.*", | ||
| "tinydb.*", | ||
| "platformdirs", | ||
| ] |
There was a problem hiding this comment.
I don't understand this list. E.g. tinydb and platformdirs both have type annotations. What is the list for?
There was a problem hiding this comment.
You're right - tinydb and platformdirs do have type annotations. I cleaned up the ignore list to only include modules that actually need it (argcomplete, dateutil, marshmallow, and tinydb for the Document import issue). Removed platformdirs from the list. (3cc87c7)
There was a problem hiding this comment.
Please check the entire list thoroughly. I found that argcomplete also provides type annotations.
There was a problem hiding this comment.
You're absolutely right! After checking, I found that argcomplete, marshmallow, tinydb, and dateutil all provide proper type annotations. I've removed the entire mypy ignore list since all libraries have type stubs available. The codebase now runs mypy cleanly without any ignores. (300d76d)
| "tinydb.*", | ||
| "platformdirs", | ||
| ] | ||
| ignore_missing_imports = true |
There was a problem hiding this comment.
The ignore_missing_imports option is needed for external libraries that don't provide complete type information (like argcomplete, dateutil, marshmallow). I've reduced the list to only modules that actually require it and explained the migration path in the README. (3cc87c7)
| category_percentage=False, | ||
| entry_sort=None, | ||
| ): | ||
| listings: list["Listing"] | None, |
There was a problem hiding this comment.
why do you put "Listing" as string here instead of using Listing class from the import?
There was a problem hiding this comment.
Changed back to using the string "Listing" instead of the imported class to avoid the circular import issue between listing.py and rich.py. The TYPE_CHECKING import pattern is the correct approach here. (3cc87c7)
| # Define order of listed properties | ||
| if recurrent: | ||
| properties = ("name", "value", "frequency", "start", "end", "category") | ||
| properties: tuple[str, str, str, str, str, str] = ( |
There was a problem hiding this comment.
just definy properties as a list[str] before the if-else block if that makes things easier
There was a problem hiding this comment.
Simplified the properties definition to use list[str] instead of the complex tuple typing. This makes the code cleaner and easier to maintain while preserving the same functionality. (3cc87c7)
@copilot work on my PR review comments |
Co-authored-by: pylipp <10617122+pylipp@users.noreply.github.com>
| ] | ||
|
|
||
| [tool.mypy] | ||
| python_version = "3.10" |
There was a problem hiding this comment.
can this be more flexible, e.g. ">=3.10" ?
There was a problem hiding this comment.
I've added requires-python = ">=3.10" to the project configuration. The mypy python_version setting only accepts single version format ("3.10"), but the project now properly declares the minimum Python version requirement. (300d76d)
| extra_checks = true | ||
|
|
||
| [[tool.mypy.overrides]] | ||
| module = [ |
There was a problem hiding this comment.
Please check the entire list thoroughly. I found that argcomplete also provides type annotations.
There was a problem hiding this comment.
Checked thoroughly - all libraries (argcomplete, marshmallow, tinydb, dateutil) provide proper type annotations. Removed the entire ignore list and mypy now passes cleanly without any ignores. (300d76d)
Co-authored-by: pylipp <10617122+pylipp@users.noreply.github.com>
Removed Python 3.9 from the CI workflow matrix and project classifiers. Also removed the Python 3.9 compatibility code from cli.py since it's no longer needed, and added |
This PR implements comprehensive type annotations throughout the financeager codebase to improve code safety and developer experience. The implementation follows modern Python typing best practices and includes full mypy integration with proper CI/CD configuration.
Key Changes
Type Annotations
financeager/directorystr | Noneinstead ofOptional[str],list[str]instead ofList[str])Python Version Requirements
requires-python = ">=3.10")MyPy Configuration
pyproject.tomlCI/CD Integration
Documentation
Technical Details
The implementation maintains 100% backward compatibility for Python 3.10+ while adding type safety. All pre-commit hooks (black, flake8, isort, mypy) pass successfully, and the mypy configuration requires no external library ignores since all dependencies provide proper type stubs.
Fixes #254.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.