Skip to content

Commit 3fd5c7c

Browse files
committed
fix mypy issues
1 parent ddb408f commit 3fd5c7c

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

logprep/processor/base/rule.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ def metrics(self):
290290
return self.Metrics(labels=self.metric_labels)
291291

292292
def __eq__(self, other: object) -> bool:
293-
return isinstance(other, Rule) and all(
294-
[other.filter == self._filter, other._config == self._config]
295-
)
293+
if not isinstance(other, Rule):
294+
return NotImplemented
295+
return all([other.filter == self._filter, other._config == self._config])
296296

297297
def __hash__(self) -> int:
298298
return id(self)

logprep/processor/pre_detector/rule.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122

123123
from functools import cached_property
124124
from types import MappingProxyType
125-
from typing import Optional, Union
125+
from typing import cast
126126
from zoneinfo import ZoneInfo
127127

128128
from attrs import asdict, define, field, fields, validators
@@ -181,11 +181,11 @@ class Config(Rule.Config): # pylint: disable=too-many-instance-attributes
181181
which can be configured in the pipeline for the pre_detector.
182182
If this field was specified, then the rule will *only* trigger in case one of
183183
the IPs from the list is also available in the specified fields."""
184-
sigma_fields: Union[list, bool] = field(
184+
sigma_fields: list | bool = field(
185185
validator=validators.instance_of((list, bool)), factory=list
186186
)
187187
"""tbd"""
188-
link: Optional[str] = field(
188+
link: str | None = field(
189189
validator=validators.optional(validators.instance_of(str)), default=None
190190
)
191191
"""A link to the rule if applicable."""
@@ -229,7 +229,7 @@ class Config(Rule.Config): # pylint: disable=too-many-instance-attributes
229229
@property
230230
def config(self) -> Config:
231231
"""Provides the properly typed rule configuration object"""
232-
return self._config
232+
return cast("PreDetectorRule.Config", self._config)
233233

234234
def __eq__(self, other: object) -> bool:
235235
if not isinstance(other, PreDetectorRule):

logprep/util/helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _add_and_not_overwrite_key(sub_dict, key):
8686
def _add_field_to(
8787
event: dict,
8888
field: tuple,
89-
rule: "Rule",
89+
rule: "Rule" | None,
9090
merge_with_target: bool = False,
9191
overwrite_target: bool = False,
9292
) -> None:
@@ -179,7 +179,7 @@ def _add_field_to_silent_fail(*args, **kwargs) -> None | str:
179179
def add_fields_to(
180180
event: dict,
181181
fields: dict,
182-
rule: "Rule" = None,
182+
rule: "Rule" | None = None,
183183
merge_with_target: bool = False,
184184
overwrite_target: bool = False,
185185
skip_none: bool = True,
@@ -525,7 +525,7 @@ def copy_fields_to_event(
525525
skip_missing: bool = True,
526526
merge_with_target: bool = False,
527527
overwrite_target: bool = False,
528-
rule: "Rule" = None,
528+
rule: "Rule" | None = None,
529529
) -> None:
530530
"""
531531
Copies fields from source_event to target_event.

0 commit comments

Comments
 (0)