From d20d07bb6a241f5d6bd2bb7e0899b4509abbbba0 Mon Sep 17 00:00:00 2001 From: profitroll Date: Tue, 29 Oct 2024 23:19:52 +0100 Subject: [PATCH] Fixed a few things mentioned in SonarCloud --- src/libbot/__main__.py | 9 +++++---- src/libbot/pyrogram/classes/client.py | 3 ++- src/libbot/sync/__main__.py | 9 +++++---- tests/test_utils.py | 2 ++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/libbot/__main__.py b/src/libbot/__main__.py index eb696e1..ffb36f3 100644 --- a/src/libbot/__main__.py +++ b/src/libbot/__main__.py @@ -11,6 +11,8 @@ except ImportError: from ._utils import supports_argument from .sync._nested import nested_delete, nested_set +DEFAULT_CONFIG_LOCATION: str = "config.json" + async def json_read(path: Union[str, Path]) -> Any: """Read contents of a JSON file @@ -43,7 +45,7 @@ async def json_write(data: Any, path: Union[str, Path]) -> None: async def config_get( - key: str, *path: str, config_file: Union[str, Path] = "config.json" + key: str, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION ) -> Any: """Get a value of the config key by its path provided For example, `foo.bar.key` has a path of `"foo", "bar"` and the key `"key"` @@ -83,7 +85,7 @@ async def config_get( async def config_set( - key: str, value: Any, *path: str, config_file: Union[str, Path] = "config.json" + key: str, value: Any, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION ) -> None: """Set config's key by its path to the value @@ -99,14 +101,13 @@ async def config_set( await json_write( nested_set(await json_read(config_file), value, *(*path, key)), config_file ) - return async def config_delete( key: str, *path: str, missing_ok: bool = False, - config_file: Union[str, Path] = "config.json", + config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION, ) -> None: """Set config's key by its path diff --git a/src/libbot/pyrogram/classes/client.py b/src/libbot/pyrogram/classes/client.py index c246434..450aa13 100644 --- a/src/libbot/pyrogram/classes/client.py +++ b/src/libbot/pyrogram/classes/client.py @@ -358,7 +358,8 @@ class PyroClient(Client): ] logger.info( - "Registering commands %s with a default scope 'BotCommandScopeDefault'" + "Registering commands %s with a default scope 'BotCommandScopeDefault'", + commands ) await self.set_bot_commands(commands) diff --git a/src/libbot/sync/__main__.py b/src/libbot/sync/__main__.py index 7ece6cb..8ab01dc 100644 --- a/src/libbot/sync/__main__.py +++ b/src/libbot/sync/__main__.py @@ -9,6 +9,8 @@ try: except ImportError: from json import dumps, loads +DEFAULT_CONFIG_LOCATION: str = "config.json" + def json_read(path: Union[str, Path]) -> Any: """Read contents of a JSON file @@ -41,7 +43,7 @@ def json_write(data: Any, path: Union[str, Path]) -> None: def config_get( - key: str, *path: str, config_file: Union[str, Path] = "config.json" + key: str, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION ) -> Any: """Get a value of the config key by its path provided For example, `foo.bar.key` has a path of `"foo", "bar"` and the key `"key"` @@ -81,7 +83,7 @@ def config_get( def config_set( - key: str, value: Any, *path: str, config_file: Union[str, Path] = "config.json" + key: str, value: Any, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION ) -> None: """Set config's key by its path to the value @@ -95,14 +97,13 @@ def config_set( * `KeyError`: Key is not found under path provided """ json_write(nested_set(json_read(config_file), value, *(*path, key)), config_file) - return def config_delete( key: str, *path: str, missing_ok: bool = False, - config_file: Union[str, Path] = "config.json", + config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION, ) -> None: """Set config's key by its path diff --git a/tests/test_utils.py b/tests/test_utils.py index c0aef75..2dc3217 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -6,10 +6,12 @@ from libbot._utils import supports_argument def func1(foo: str, bar: str): + """Dummy function with specific arguments""" pass def func2(foo: str): + """Dummy function with specific arguments""" pass