-
Notifications
You must be signed in to change notification settings - Fork 0
Improve json service base with proper list support #3
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
base: main
Are you sure you want to change the base?
Improve json service base with proper list support #3
Conversation
WalkthroughThe project has been enhanced with a new testing function for the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review Status
Configuration used: CodeRabbit UI
Files selected for processing (6)
- scripts/main.py (1 hunks)
- src/jsonservice/init.py (1 hunks)
- src/jsonservice/dictservice.py (1 hunks)
- src/jsonservice/jsonservice.py (1 hunks)
- src/jsonservice/jsonservice_base.py (1 hunks)
- src/jsonservice/listservice.py (1 hunks)
Files skipped from review due to trivial changes (1)
- src/jsonservice/init.py
Additional comments not posted (4)
scripts/main.py (1)
11-28
: Consider renamingtest_json_service_dict()
todemo_json_service_dict()
and adding assertions to validate the expected outcomes for a more robust demonstration.src/jsonservice/jsonservice.py (1)
19-23
: The delegation of read and write operations to the appropriate service instance is correctly implemented.src/jsonservice/jsonservice_base.py (1)
2-31
: Consider using theabc
module to makeJsonServiceBase
an abstract base class and enforce method implementation in subclasses.src/jsonservice/dictservice.py (1)
9-71
: The implementation ofJsonDictService
is well-structured. Consider adding error handling for file operations to improve robustness.
def __init__(self, json_path: str, create_if_not_exists: bool = True, default_type: type | None = None): | ||
if default_type is not None and default_type not in [dict, list]: | ||
print("Default type can only be dict or list!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace exit(1)
with raising a ValueError
for invalid default_type
to allow exception handling by the caller.
- print("Default type can only be dict or list!")
- exit(1)
+ raise ValueError("Default type can only be dict or list!")
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def __init__(self, json_path: str, create_if_not_exists: bool = True, default_type: type | None = None): | |
if default_type is not None and default_type not in [dict, list]: | |
print("Default type can only be dict or list!") | |
def __init__(self, json_path: str, create_if_not_exists: bool = True, default_type: type | None = None): | |
if default_type is not None and default_type not in [dict, list]: | |
raise ValueError("Default type can only be dict or list!") |
def write(self, path: str, value): | ||
pass | ||
|
||
def read(self, key): | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement the write
and read
methods or clarify they are placeholders if intentional.
Summary by CodeRabbit
New Features
JsonService
class supporting both dictionary and list data structures.JsonService
class.Refactor
JsonService
class to accept adefault_type
parameter, enhancing its versatility with different data types.Documentation
jsonservice
module for clearer usage.