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

refactor(customize): improve code readability #1412

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

Merged
Lee-W merged 1 commit into commitizen-tools:master from bearomorphism:refactor-customize
May 22, 2025

Conversation

Copy link
Contributor

@bearomorphism bearomorphism commented May 14, 2025
edited
Loading

Description

Make the code shorter but still easy to read.

Checklist

  • Add test cases to all the changes you introduce
  • Run poetry all locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes

Expected behavior

NA, this is refactor.

Steps to Test This Pull Request

Additional context

NA

Copy link

codecov bot commented May 14, 2025
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.59%. Comparing base (120d514) to head (e163049).
Report is 621 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@
## master #1412 +/- ##
==========================================
+ Coverage 97.33% 97.59% +0.25% 
==========================================
 Files 42 57 +15 
 Lines 2104 2657 +553 
==========================================
+ Hits 2048 2593 +545 
- Misses 56 64 +8 
Flag Coverage Δ
unittests 97.59% <100.00%> (+0.25%) ⬆️

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.

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

Copy link
Contributor Author

bearomorphism commented May 15, 2025
edited
Loading

I was curious about the difference between .get("some_key", "") and .get("some_key") or ""

https://chatgpt.com/share/68254494-f83c-8010-8ab3-7f8808682bcf

probably not important

Copy link
Member

I was curious about the difference between .get("some_key", "") and .get("some_key") or ""

Actually, it matters: if you have some_key: in your settings, meaning empty key in yaml, the key exists and the first one returns None while the second one returns "".
The second approach is most of the time safer is it ensure all falsy values will and with the same type:

yaml .get("key", "") .get("key") or ""
Not set "" ""
key: "" "" ""
key: None ""
key: false False ""
key: 0 0 ""
key: [] [] ""
key: {} {} ""
key: no (yaml 1.1) False ""

So it really depends on your case, but if there is no default value, and you want to be sure of the type you have in case of falsy value, go for the 2nd.

bearomorphism, Lee-W, and woile reacted with thumbs up emoji

Copy link
Contributor Author

bearomorphism commented May 15, 2025
edited
Loading

I was curious about the difference between .get("some_key", "") and .get("some_key") or ""

Actually, it matters: if you have some_key: in your settings, meaning empty key in yaml, the key exists and the first one returns None while the second one returns "". The second approach is most of the time safer is it ensure all falsy values will and with the same type:

yaml .get("key", "") .get("key") or ""
Not set "" ""
key: "" "" ""
key: None ""
key: false False ""
key: 0 0 ""
key: [] [] ""
key: {} {} ""
key: no (yaml 1.1) False ""
So it really depends on your case, but if there is no default value, and you want to be sure of the type you have in case of falsy value, go for the 2nd.

Thank you for explanation. Actually, the thing I'm not sure is if we want to fallback to empty string if the value is falsy (current implementation).

Copy link
Member

noirbizarre commented May 15, 2025
edited
Loading

I think this has been a recurrent discussion on reviews: we have some improvements to do on the "cli flags > user settings > default value" cascading handling:

  • lots of repetitions
  • sometimes we have the same setting with different behavior depending on the command
  • ...

There is room for improvement.
But we have to maintain backward compatibility, so the day we change that, it might be a breaking change.

Copy link
Member

Lee-W commented May 16, 2025

I think this has been a recurrent discussion on reviews: we have some improvements to do on the "cli flags > user settings > default value" cascading handling:

* lots of repetitions
* sometimes we have the same setting with different behavior depending on the command
* ...

There is room for improvement. But we have to maintain backward compatibility, so the day we change that, it might be a breaking change.

I've also wanted to rewrite the whole setting, default value thing....

noirbizarre, woile, and bearomorphism reacted with thumbs up emoji

Copy link
Contributor Author

I think this has been a recurrent discussion on reviews: we have some improvements to do on the "cli flags > user settings > default value" cascading handling:

* lots of repetitions
* sometimes we have the same setting with different behavior depending on the command
* ...

There is room for improvement. But we have to maintain backward compatibility, so the day we change that, it might be a breaking change.

I've also wanted to rewrite the whole setting, default value thing....

I can try this. We can discuss when you have time.

Copy link
Member

Lee-W commented May 22, 2025

Created an issue #1445 to track and discuss this redesign, probably will go to v5

@Lee-W Lee-W merged commit d0c2674 into commitizen-tools:master May 22, 2025
18 checks passed
@bearomorphism bearomorphism deleted the refactor-customize branch June 1, 2025 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@Lee-W Lee-W Lee-W approved these changes

@woile woile Awaiting requested review from woile woile is a code owner

@noirbizarre noirbizarre Awaiting requested review from noirbizarre noirbizarre is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /