Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

CLI Serialization Fixes#649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
kschwab wants to merge3 commits intopydantic:main
base:main
Choose a base branch
Loading
fromkschwab:cli-serialize-subcommand

Conversation

kschwab
Copy link
Contributor

  • Adds serialization of sub commands.
  • Fixes serialization of kebab case of flags.

@hramezani
Copy link
Member

Thanks@kschwab

Is it a fix for an issue?

@kschwab
Copy link
ContributorAuthor

@hramezani yes, it is an issue I found locally. I can open a formal ticket if you would like.

CliApp.serialize is incorrect whencli_kebab_case is enabled. Currently on main it will do the below:

frompydantic_settingsimportBaseSettings,CliAppclassCfg(BaseSettings,cli_kebab_case=True):foo_kebab:int=123args=CliApp.serialize(Cfg())print(args)#> ['--foo_kebab', '123']CliApp.run(Cfg,cli_args=args)"""usage: example.py [-h] [--foo-kebab int]example.py: error: unrecognized arguments: --foo_kebab 123"""

With this fix, it will correctly apply the kebab case to serialization:

frompydantic_settingsimportBaseSettings,CliAppclassCfg(BaseSettings,cli_kebab_case=True):foo_kebab:int=123print(CliApp.serialize(Cfg()))#> ['--foo-kebab', '123']print(CliApp.run(Cfg,cli_args=args))#> foo_kebab=123

I also missed serialization of subcommands, which addressed as well in this PR. See addedtest.

@kschwabkschwab marked this pull request as draftJuly 3, 2025 02:05
@kschwab
Copy link
ContributorAuthor

I also just noticed thatcli_implicit_flags case will also likely need an adjustment.

@kschwabkschwabforce-pushed thecli-serialize-subcommand branch fromfa35ea9 toe985e22CompareJuly 15, 2025 14:25
@kschwabkschwab changed the titleCLI Support for Subcommand SerializationCLI Serialization FixesJul 16, 2025
@kschwabkschwab marked this pull request as ready for reviewJuly 16, 2025 14:56
@kschwab
Copy link
ContributorAuthor

Ok@hramezani, this is ready for review again. When I looked closer, there were a handful of bugs I found with the original serialization. The change set looks larger then it is. Ireverted the original serialization implementation, and consolidated it into two standalone functions.

The bugs I found and fixed were:

  • Serializationordering could be wrong. i.e., ordering of positionals and subcommands has to be strictly maintained.
  • Skip serialization ofdefaults. Only modified values should be serialized.
  • Handle serialization ofkebab case.
  • Handleimplicit bool flags.

All the newly added tests currently fail on main.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@kschwab@hramezani

[8]ページ先頭

©2009-2025 Movatter.jp