Skip to content

Apply only passed arguments and warn about skipped fields on use - #45

Merged
timkpaine merged 1 commit into
mainfrom
warn-for-passed-arguments
Nov 14, 2026
Merged

timkpaine merged 1 commit into
mainfrom
warn-for-passed-arguments

Conversation

@timkpaine

Copy link
Copy Markdown
Member

Description

Three changes to parse_extra_args_model, found through the warnings hatch-cpp prints in each build:

  • Warnings for skipped fields. p2a warned at parse time about each field it could not map to an argument, including empty lists of models (libraries, artifacts). A plugin user cannot act on that. The reason is now logged at debug level, and the warning is printed only when an argument for that field is passed, for example --artifacts.0.name x. The message text is unchanged.
  • Unpassed arguments. p2a applied the default of each argument that was not passed. That had three effects: a falsy value on the instance was reset to the field default (flag: bool = True set to False came back as True), an indexed list argument such as --values.0 9 was overwritten by the list default, and optional dict fields printed Failed to validate field. The parser used for a model now leaves unpassed arguments out of the result. create_model_parser still returns a parser with defaults.
  • Lists of paths. list[Path] is handled like list[str].

With hatch-cpp 0.6.0, a libraries build goes from 5 warnings to 0 and a CMake build from 3 to 0. The hatch-cpp test suite passes against this branch.

hatch-build has a test that expects the old warnings without passing the arguments. python-project-templates/hatch-build needs its test updated before a p2a release with this change.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / code cleanup
  • CI / build configuration
  • Other (describe below)

Checklist

  • Linting passes (make lint)
  • Tests pass (make test)
  • New tests added for new functionality
  • Documentation updated (if applicable)
  • Changelog / version bump (if applicable)

parse_extra_args_model warned at parse time about each field it could
not map to an argument, including empty lists of models, so a plugin
built on it printed the same warnings in each build. The reasons are
now logged at debug level, and a warning is printed only when an
argument for a skipped field is passed.

It also applied the default of each argument that was not passed. That
reset a falsy value on the instance to the field default, replaced
indexed list arguments with the list default, and printed a validation
warning for optional dict fields. Arguments that are not passed are now
left out of the parsed result. create_model_parser keeps its defaults.

Lists of paths are supported like lists of strings.

Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

5 tests  +3   5 ✅ +3   0s ⏱️ ±0s
1 suites ±0   0 💤 ±0 
1 files   ±0   0 ❌ ±0 

Results for commit d50c026. ± Comparison against base commit ee416e9.

@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.52%. Comparing base (ee416e9) to head (d50c026).

Files with missing lines Patch % Lines
p2a/model.py 87.17% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #45      +/-   ##
==========================================
+ Coverage   83.60%   84.52%   +0.92%     
==========================================
  Files           3        3              
  Lines         372      420      +48     
  Branches       93       94       +1     
==========================================
+ Hits          311      355      +44     
- Misses         35       38       +3     
- Partials       26       27       +1     

☔ 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.

@timkpaine
timkpaine merged commit 292d533 into main Nov 14, 2026
4 checks passed
@timkpaine
timkpaine deleted the warn-for-passed-arguments branch November 14, 2026 00:54
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.

1 participant