Skip to content

Dataclass-like types accept the same values whether or not added as a group - #952

Merged
mauvilsa merged 1 commit into
mainfrom
fix-dataclass-like-subclass-spec-asymmetry
Aug 11, 2026
Merged

Dataclass-like types accept the same values whether or not added as a group#952
mauvilsa merged 1 commit into
mainfrom
fix-dataclass-like-subclass-spec-asymmetry

Conversation

@mauvilsa

Copy link
Copy Markdown
Owner

What does this PR do?

A dataclass-like type is added as an argument group when it is the entire type of an
argument (each field becomes its own option, e.g. --data.number), but as a single
typehint argument when it is part of a larger type (e.g. Optional[Data],
list[Data]). The accepted values differed between these two cases. This PR makes them
consistent and fixes several related issues.

Changed

  • A dataclass-like type added as a group now accepts a subclass spec with the
    class_path of the type itself, e.g. --data='{"class_path": "Data", "init_args": {...}}', instead of failing with Group 'data' does not accept option 'init_args....'.

Fixed

  • A dataclass-like type not added as a group, e.g. Optional[Data], accepted the
    class_path of a subclass, even though subclasses are disabled for these types by
    default. The error now explains how to enable subclass support.
  • Signature parameters typed as a non-group dataclass-like type (Optional[Data],
    list[Data], dict[str, Data]) did not accept a path to a sub-config file even with
    sub_configs=True, failing with e.g. No module named 'data'. Also, the path of a
    loaded sub-config was not kept, so save with multifile=True did not write it back
    to its own file.
  • Environment variable values for a dataclass-like argument of a subcommand, e.g.
    APP_SUB__DATA='{"p1": 2}', failed with Not a valid subclass of ....

Added

  • shtab completion scripts now include the fields of a dataclass-like type that is not
    added as a group.

Documentation updated in the subclasses-disabled and sub-config-files sections; new
tests in test_dataclasses.py, test_paths.py, test_pydantic.py, test_shtab.py and
test_subcommands.py.

Before submitting

  • Did you read the contributing guideline?
  • If you used a coding agent, did you fully understand and validate all generated code and ensure it follows the contributing guidelines?
  • Did you update the documentation? (readme and public docstrings)
  • Did you write unit tests such that there is 100% coverage on related code? (required for bug fixes and new features)
  • Did you verify that new and existing tests pass locally?
  • If this is a bug fix, did you verify that the tests fail without the code fix?
  • Did you make sure that all changes preserve backward compatibility?
  • Did you update the CHANGELOG including a pull request link? (not for typos, docs, test updates, or minor internal changes/refactors)

@mauvilsa mauvilsa added bug Something isn't working enhancement New feature or request labels Aug 11, 2026
@mauvilsa
mauvilsa deployed to sonarcloud August 11, 2026 05:27 — with GitHub Actions Active
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (79d9e3e) to head (693af19).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #952   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         8252      8305   +53     
=========================================
+ Hits          8252      8305   +53     

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

@mauvilsa
mauvilsa merged commit 7a860bf into main Aug 11, 2026
32 checks passed
@mauvilsa
mauvilsa deleted the fix-dataclass-like-subclass-spec-asymmetry branch August 11, 2026 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant