Create a safer abstraction for TypeAdapter validation#1762
Open
Create a safer abstraction for TypeAdapter validation#1762
Conversation
…r_default wrappers Migrate all direct TypeAdapter usage in business logic files to the new validate_or_raise and validate_or_default wrappers from usethis._validate. Updated files: - _file/pyproject_toml/name.py, project.py, deps.py, requires_python.py - _core/status.py - _tool/impl/base/ruff.py, deptry.py - _integrations/sonarqube/config.py - _backend/uv/deps.py Also added TID251 per-file-ignores for the I/O infrastructure files (ini/io_.py, toml/io_.py, yaml/io_.py) which use TypeAdapter extensively in their core dict-traversal logic. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
…n file I/O managers Replace all direct pydantic TypeAdapter/ValidationError usage in toml/io_.py, yaml/io_.py, and ini/io_.py with the validate_or_raise wrapper from usethis._validate. - toml/io_.py: Replace TypeAdapter calls, catch TOMLValueInvalidError - yaml/io_.py: Replace TypeAdapter calls, catch UnexpectedYAMLValueError - ini/io_.py: Replace TypeAdapter calls with validate_or_raise - ruff.toml: Remove TID251 per-file-ignores for the three files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/be6062d4-5e4e-4744-9771-ce15eb74e895 Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/be6062d4-5e4e-4744-9771-ce15eb74e895 Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Create a safer abstraction for TypeAdapter validation
Create safer abstraction for TypeAdapter validation
Apr 2, 2026
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
nathanjmcdougall
requested changes
Apr 2, 2026
…to KeyValueFileManager Per review feedback: - Move src/usethis/_validate.py -> src/usethis/_file/validate.py - Add get_validated(keys, *, default, validate=None) method - Add ensure_get(keys, *, err, validate) method - Replace direct validate_or_default usage in tool/core/backend files with the new file manager methods - Update .importlinter, tests, and generated docs Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/ae5b883a-a133-47ce-a8c8-86903ff6c49e Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
nathanjmcdougall
requested changes
Apr 3, 2026
Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/74ba0f75-c2cd-45aa-b890-dc8228ec2711 Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
nathanjmcdougall
requested changes
Apr 3, 2026
Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/1564655d-dd00-4582-9f0f-e08225210e9e Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
… ensure_get/validated_get in pyproject_toml and sonarqube modules Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/1564655d-dd00-4582-9f0f-e08225210e9e Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Collaborator
|
@copilot please pass static checks |
…-substrings) Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/07093d4e-1e91-49fb-9686-b3e141b83d29 Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Contributor
Author
nathanjmcdougall
requested changes
Apr 8, 2026
…move test class docstrings Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/690b9dc0-c97a-46d2-b952-6bf84cfe9131 Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
…toml Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/20e757e7-c8ce-492d-a26d-a4b03ec79027 Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
nathanjmcdougall
requested changes
Apr 9, 2026
…t for invalid configs, remove unused SonarQubeError base class Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/c1bb2774-9802-4976-9c81-851b72ce5735 Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
…cted Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/c1bb2774-9802-4976-9c81-851b72ce5735 Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
…s still actively raised Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/2d2991c3-9149-42d5-962f-11a9b2a29d3a Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
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.
validate_or_raise,validate_or_default)validated_getandensure_getconvenience methods onKeyValueFileManagerTypeAdapter.validate_pythonusages with safe wrapperspydantic.TypeAdapterimport via TID251@overloadtovalidate_or_raisefor better type narrowingvalidate_or_raiseto accepterrarg (instantiated error)get_project_dict()call chain and match main's error propagationwarn_msgparameter tovalidate_or_default— emitswarn_printon validation failurewarn_msgparameter tovalidated_get— passes through tovalidate_or_defaultdeps.pyto usevalidated_getwithwarn_msg(warns on invalid type instead of raising)PyprojectTOMLDepsError/DepGroupErrorcatch blocks in_deps.pyPyprojectTOMLDepsErrorclass# noqa: TID251comments instead of per-file ignoresTestGetValidatedandTestEnsureGettotest_manager.pyunderTestKeyValueFileManagerValidationErrordetails intoerrmessage invalidate_or_raiseValidationErrordetails intowarn_msginvalidate_or_defaultInvalidSonarQubeProjectKeyErrorsubclass (no longer raised); restoreSonarQubeErrorbase classwarn_printfor invalid values in yaml/io_.py and toml/io_.py getter methodsSkills used:
usethis-qa-static-checks,usethis-github-issue-create