Skip to content

Commit f8e44c4

Browse files
authored
Merge pull request #605 from powerapi-ng/refactor/implicit-optional-type-hints
refactor: Use union types syntax to define optional arguments
2 parents c1fdb8c + 20639a6 commit f8e44c4

File tree

7 files changed

+11
-13
lines changed

7 files changed

+11
-13
lines changed

.ruff.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,5 @@ ignore = [
1818

1919
"B006", # mutable-argument-default
2020
"F401", # unused-import
21-
"RUF013", # implicit-optional
22-
2321
"B010", # set-attr-with-constant
2422
]

src/powerapi/cli/config_parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
get_longest_related_suffix
4444

4545

46-
def store_val(argument_name: str, val: Any, configuration: dict, args: list = None) -> (list, dict):
46+
def store_val(argument_name: str, val: Any, configuration: dict, args: list | None = None) -> (list, dict):
4747
"""
4848
Action that stores the value of the argument on the parser result
4949
@@ -55,7 +55,7 @@ def store_val(argument_name: str, val: Any, configuration: dict, args: list = No
5555
return args, configuration
5656

5757

58-
def store_true(argument_name: str, configuration: dict, val: Any = None, args: list = None) -> (list, dict):
58+
def store_true(argument_name: str, configuration: dict, val: Any = None, args: list | None = None) -> (list, dict):
5959
"""
6060
Action that stores a True boolean value on the parser result
6161
@@ -65,7 +65,7 @@ def store_true(argument_name: str, configuration: dict, val: Any = None, args: l
6565
return args, configuration
6666

6767

68-
def extract_file_names(argument_name: str, val: Any, configuration: dict, args: list = None):
68+
def extract_file_names(argument_name: str, val: Any, configuration: dict, args: list | None = None):
6969
"""
7070
Action used to convert string from --files parameter into a list of file name
7171
"""
@@ -79,7 +79,7 @@ class ConfigurationArgument:
7979
"""
8080

8181
def __init__(self, names: list, is_flag: bool, default_value: Any, help_text: str, argument_type: type,
82-
is_mandatory: bool, action: Callable = None):
82+
is_mandatory: bool, action: Callable | None = None):
8383
self.names = names
8484
self.is_flag = is_flag
8585
self.default_value = default_value

src/powerapi/cli/generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class ProcessorGenerator(Generator):
287287
Generator that initialises the processor from config
288288
"""
289289

290-
def __init__(self, component_group_name: str, processor_factory: dict[str, Callable[[dict], ProcessorActor]] = None):
290+
def __init__(self, component_group_name: str, processor_factory: dict[str, Callable[[dict], ProcessorActor]] | None = None):
291291
Generator.__init__(self, component_group_name)
292292

293293
self.processor_factory = processor_factory

src/powerapi/cli/parsing_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def validate(self, conf: dict) -> dict:
190190

191191
return conf
192192

193-
def parse(self, args: list = None) -> dict:
193+
def parse(self, args: list | None = None) -> dict:
194194
"""
195195
Parse the configurations defined via le CLI, Environment Variables and configuration file.
196196
The priority of defined values is the following:

src/powerapi/database/base_db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class BaseDB:
7373
This class define the interface needed to fetch/save reports from/to a database.
7474
"""
7575

76-
def __init__(self, report_type: type[Report], exceptions: list[type[Exception]] = None):
76+
def __init__(self, report_type: type[Report], exceptions: list[type[Exception]] | None = None):
7777
"""
7878
:param report_type: The type of report expected
7979
:param exceptions: List of exception type raised by the database module

src/powerapi/processor/pre/k8s/actor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class K8sPreProcessorState(ProcessorState):
4545
State of the Kubernetes pre-processor actor.
4646
"""
4747

48-
def __init__(self, actor: Actor, target_actors: list, target_actors_names: list, api_mode: str, api_host: str, api_key: str):
48+
def __init__(self, actor: Actor, target_actors: list, target_actors_names: list, api_mode: str | None, api_host: str | None, api_key: str | None):
4949
super().__init__(actor, target_actors, target_actors_names)
5050

5151
self.api_mode = api_mode
@@ -71,8 +71,8 @@ class K8sPreProcessorActor(ProcessorActor):
7171
Pre-Processor Actor that adds Kubernetes related metadata to reports.
7272
"""
7373

74-
def __init__(self, name: str, target_actors: list, target_actors_names: list, api_mode: str = None, api_host: str = None,
75-
api_key: str = None, level_logger: int = logging.WARNING, timeout: int = 5000):
74+
def __init__(self, name: str, target_actors: list, target_actors_names: list, api_mode: str | None = None,
75+
api_host: str | None = None, api_key: str | None = None, level_logger: int = logging.WARNING, timeout: int = 5000):
7676
super().__init__(name, level_logger, timeout)
7777

7878
self.state = K8sPreProcessorState(self, target_actors, target_actors_names, api_mode, api_key, api_host)

src/powerapi/processor/pre/k8s/monitor_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def fetch_list_all_pod_for_all_namespaces(self) -> int | None:
204204

205205
return resource_version
206206

207-
def watch_list_pod_for_all_namespaces(self, resource_version: int = None):
207+
def watch_list_pod_for_all_namespaces(self, resource_version: int | None = None):
208208
"""
209209
Watch k8s pods events for all namespaces and update the local metadata cache accordingly.
210210
:param resource_version: Resource version from where the watcher begin

0 commit comments

Comments
 (0)