Skip to content

Raise ArgumentTypeError for non-string variant choices - #131

Draft
sapunyangkut wants to merge 2 commits into
deepmodeling:masterfrom
sapunyangkut:codex/issue-119-nonstring-choice-errors
Draft

Raise ArgumentTypeError for non-string variant choices#131
sapunyangkut wants to merge 2 commits into
deepmodeling:masterfrom
sapunyangkut:codex/issue-119-nonstring-choice-errors

Conversation

@sapunyangkut

@sapunyangkut sapunyangkut commented Jul 16, 2026

Copy link
Copy Markdown

Summary

  • validate a variant tag's type before alias dictionary membership or spelling suggestions
  • raise the structured ArgumentTypeError for list, mapping, numeric, and null tags instead of leaking raw TypeError
  • preserve alias normalization and Did you mean behavior for string values

Fixes #119.

Validation

  • focused regression: 1 passed on the exact upstream base and patch
  • adjacent checker tests: 13 passed on the exact upstream base and patch
  • full suite: 50 passed on the exact upstream base and patch
  • git diff --check, Python AST checks, and a bounded manual security review passed in the publication worktree
  • the current publication environment could not recollect pytest because typeguard is not installed; no dependencies were installed for this submission

AI assistance disclosure

This change was prepared and tested with OpenAI Codex. It is intentionally opened as a Draft for maintainer review. No automated issue/PR comments or Ready transition will be made.

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation for variant choices, including clearer errors when values use an unsupported type.
    • Enhanced suggestions for misspelled choice tags.
    • Ensured aliases consistently resolve to their corresponding canonical choices.
  • Tests

    • Added coverage for invalid types, aliases, and misspelled choice suggestions.

sapunyangkut and others added 2 commits July 16, 2026 20:31
Validate variant tags before alias lookup or spelling suggestions so invalid list, mapping, numeric, and null values raise ArgumentTypeError instead of raw TypeError.

AI-assisted by OpenAI Codex; submitted as a Draft for maintainer review.
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3aa1c16c-f7eb-4c44-b777-00d818f6a6da

📥 Commits

Reviewing files that changed from the base of the PR and between b4db564 and 26b4aa9.

📒 Files selected for processing (2)
  • dargs/dargs.py
  • tests/test_checker.py

📝 Walkthrough

Walkthrough

Variant choice handling now rejects non-string discriminator values with structured type errors, includes aliases in expected-choice suggestions, preserves alias normalization, and adds tests for invalid types, aliases, and misspelled tags.

Changes

Variant choice validation

Layer / File(s) Summary
Choice type and alias handling
dargs/dargs.py, tests/test_checker.py
Variant validates string discriminator values, combines direct tags and aliases for suggestions, restricts alias conversion to strings, and tests the resulting errors and normalization.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: validating non-string variant choices with ArgumentTypeError.
Linked Issues check ✅ Passed The changes address #119 by rejecting non-string variant tags with structured ArgumentTypeError and preserving value suggestions.
Out of Scope Changes check ✅ Passed The edits stay focused on variant choice validation and its tests, with no明显 unrelated scope added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.23%. Comparing base (b4db564) to head (26b4aa9).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #131      +/-   ##
==========================================
+ Coverage   75.14%   75.23%   +0.08%     
==========================================
  Files           9        9              
  Lines         853      856       +3     
==========================================
+ Hits          641      644       +3     
  Misses        212      212              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

[Code scan] Non-string variant choices raise raw TypeError

1 participant