837 handle unexpected non mappings better in toml files#840
Merged
nathanjmcdougall merged 10 commits intomainfrom Jul 10, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances error handling for TOML operations by introducing TOMLValueInvalidError, catching ValidationError in key lookup and modification methods, and adding tests for non-mapping and non-list scenarios.
- Added a new exception type (
TOMLValueInvalidError) and updatedio_.pymethods to raise it orTOMLValueMissingErrorwhen encountering invalid or missing data types. - Extended test coverage in
test_toml_io_.pyandtest_author.pyto cover scalar vs. mapping and invalid list scenarios. - Adjusted INI error definitions to align with the new invalid-value pattern.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/usethis/integrations/file/toml/test_toml_io.py | Added tests for contains, getitem, set, delete, extend/remove under non-mapping/list conditions |
| tests/usethis/_core/test_author.py | Added tests for project/authors sections being wrong types in add_author |
| src/usethis/integrations/file/toml/io.py | Caught ValidationError in __contains__, __getitem__, set_value, __delitem__, extend_list, and remove_from_list to raise new error types |
| src/usethis/_integrations/file/toml/errors.py | Introduced TOMLValueInvalidError for invalid TOML value situations |
| src/usethis/_integrations/file/ini/errors.py | Fixed INI missing-error doc, added INIValueInvalidError, and updated InvalidINITypeError hierarchy |
Comments suppressed due to low confidence (2)
src/usethis/_integrations/file/ini/errors.py:42
- [nitpick] Inheriting
InvalidINITypeErrorfrom bothINIStructureErrorandINIValueInvalidErrormay blur exception semantics; consider separating structural errors from invalid value errors or adjusting the hierarchy for clarity.
class InvalidINITypeError(TypeError, INIStructureError, INIValueInvalidError):
src/usethis/integrations/file/toml/io.py:194
- [nitpick] Consider reintroducing validation on
parent(e.g., usingTypeAdapter(dict).validate_python(parent)) before assigning to ensure the overwritten container is a mapping and to avoid potential type errors at runtime.
parent[keys[-1]] = value
Codecov ReportAll modified and coverable lines are covered by tests ✅ ✅ All tests successful. No failed tests found. 📢 Thoughts on this report? Let us know! |
CodSpeed Instrumentation Performance ReportMerging #840 will not alter performanceComparing Summary
|
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.