Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2333. Remove not none arg parse defaults. #2334

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ilovelinux
Copy link
Contributor

@ilovelinux ilovelinux commented Mar 4, 2025

Steps

  • Remove not None arg parse defaults
  • Check that default values for those options, provided in __main__.Config, are the same.

Fix #2333

Breaking changes

None

@ilovelinux ilovelinux changed the title Fix #2333. Remove not none arg parse defaults. Fix https://github.com/koxudaxi/datamodel-code-generator/issues/2333. Remove not none arg parse defaults. Mar 4, 2025
@ilovelinux ilovelinux changed the title Fix https://github.com/koxudaxi/datamodel-code-generator/issues/2333. Remove not none arg parse defaults. Fix #2333. Remove not none arg parse defaults. Mar 4, 2025
@ilovelinux ilovelinux force-pushed the fix/2333-ilovelinux-fix-defaults branch from aee8044 to 81fce3f Compare March 4, 2025 10:04
Copy link
Collaborator

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests validating the change.

@ilovelinux ilovelinux requested a review from gaborbernat March 4, 2025 17:51
Copy link

codspeed-hq bot commented Mar 4, 2025

CodSpeed Performance Report

Merging #2334 will not alter performance

Comparing ilovelinux:fix/2333-ilovelinux-fix-defaults (17b9a3c) with main (ef0c97c)

Summary

✅ 31 untouched benchmarks

Copy link

codecov bot commented Mar 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.39%. Comparing base (ef0c97c) to head (17b9a3c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2334   +/-   ##
=======================================
  Coverage   98.39%   98.39%           
=======================================
  Files          65       65           
  Lines        7792     7798    +6     
  Branches      775      776    +1     
=======================================
+ Hits         7667     7673    +6     
  Misses         91       91           
  Partials       34       34           
Flag Coverage Δ
unittests 98.39% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@ilovelinux ilovelinux force-pushed the fix/2333-ilovelinux-fix-defaults branch from 883b50d to 17b9a3c Compare March 4, 2025 17:55
@@ -71,6 +71,19 @@ def test_show_help_when_no_input(mocker: MockerFixture) -> None:
assert print_help_mock.called


def test_no_args_has_default(monkeypatch: pytest.MonkeyPatch) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right test. We want to see that the pyprojct.toml values are respected, not that no values have default values.

Copy link
Contributor Author

@ilovelinux ilovelinux Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know but... Do you have any idea how to test that for all values without setting them by hand? I can't find a way to test the code in __main__.py easily.

pyproject_config = _get_pyproject_toml_config(Path.cwd())
if pyproject_config is not None:
pyproject_toml = {k.replace("-", "_"): v for k, v in pyproject_config.items()}
else:
pyproject_toml = {}
try:
config = Config.parse_obj(pyproject_toml)
config.merge_args(namespace)
except Error as e:
print(e.message, file=sys.stderr) # noqa: T201
return Exit.ERROR

This tests ensure that if a parameter is not given, then namespace has no parameters set. This will ensure that no values from pyproject.toml (L373) is overwritten (L374)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC: @koxudaxi

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.

[Regression] Not None default values for arg_parse override settings in pyproject.toml
2 participants