Skip to content

Commit

Permalink
refactor: replace json.loads() with json.load() (#26)
Browse files Browse the repository at this point in the history
The `json` module provides two ways to read JSON data: a `.loads()` method that accepts a JSON string, and a `.load()` method, that works on files directly. So instead of reading a file manually and passing it to `json.loads()`, it is

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
  • Loading branch information
deepsource-autofix[bot] authored Jan 9, 2024
1 parent 077c876 commit ac95df7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/plugins/nonebot_plugin_addFriend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async def _(bot: Bot, event: MessageEvent, args: Message = CommandArg()):
global config
# 下个版本把其他俩json也重载一下,不知道为啥这次就不想改
with open(configPath, 'r', encoding='utf-8') as fp:
config = json.loads(fp.read())
config = json.load(fp)
check_dict_key_bot_id(config, requestorDict, numDict, bot)
text = event.get_plaintext().strip()
argsText = args.extract_plain_text().strip()
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/nonebot_plugin_addFriend/configUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def readData(path, content=None, update=0) -> dict:
with open(path, "w", encoding="utf-8") as fp:
json.dump(content, fp, ensure_ascii=False)
with open(path, "r", encoding="utf-8") as fp:
data = json.loads(fp.read())
data = json.load(fp)
return data


Expand Down

0 comments on commit ac95df7

Please sign in to comment.