Skip to content

837 handle unexpected non mappings better in toml files#840

Merged
nathanjmcdougall merged 10 commits intomainfrom
837-handle-unexpected-non-mappings-better-in-toml-files
Jul 10, 2025
Merged

837 handle unexpected non mappings better in toml files#840
nathanjmcdougall merged 10 commits intomainfrom
837-handle-unexpected-non-mappings-better-in-toml-files

Conversation

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

No description provided.

@nathanjmcdougall nathanjmcdougall linked an issue Jul 10, 2025 that may be closed by this pull request
@nathanjmcdougall nathanjmcdougall requested a review from Copilot July 10, 2025 20:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 updated io_.py methods to raise it or TOMLValueMissingError when encountering invalid or missing data types.
  • Extended test coverage in test_toml_io_.py and test_author.py to 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 InvalidINITypeError from both INIStructureError and INIValueInvalidError may 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., using TypeAdapter(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
Copy link
Copy Markdown

codecov bot commented Jul 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Jul 10, 2025

CodSpeed Instrumentation Performance Report

Merging #840 will not alter performance

Comparing 837-handle-unexpected-non-mappings-better-in-toml-files (7bdc655) with main (fdb7a55)

Summary

✅ 2 untouched benchmarks

@nathanjmcdougall nathanjmcdougall merged commit 7316d03 into main Jul 10, 2025
20 checks passed
@nathanjmcdougall nathanjmcdougall deleted the 837-handle-unexpected-non-mappings-better-in-toml-files branch July 10, 2025 21:33
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.

Handle unexpected non-mappings better in TOML files

2 participants