Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bearomorphism
Copy link
Contributor

@bearomorphism bearomorphism commented May 14, 2025

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

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.59%. Comparing base (120d514) to head (e163049).
Report is 608 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.

@bearomorphism
Copy link
Contributor Author

bearomorphism commented May 15, 2025

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

Comment on lines -86 to +70
info_path = self.custom_settings.get("info_path")
info = self.custom_settings.get("info")
if info_path:
if info_path := self.custom_settings.get("info_path"):
with open(info_path, encoding=self.config.settings["encoding"]) as f:
content = f.read()
return content
elif info:
return info
return ""
return f.read()
return self.custom_settings.get("info") or ""
Copy link
Member

Choose a reason for hiding this comment

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

Yes, this one was clearly overly complicated 😅

@noirbizarre
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
Copy link
Contributor Author

bearomorphism commented May 15, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants