Skip to content

Commit 1b9fda0

Browse files
committed
fix: use is kwargs in constructors, improve typing.
Fix #1375
1 parent d806449 commit 1b9fda0

2 files changed

Lines changed: 171 additions & 112 deletions

File tree

pymisp/abstract.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class AbstractMISP(MutableMapping, MISPFileCache, metaclass=ABCMeta): # type: i
9797
__misp_objects_path = misp_objects_path
9898
__describe_types = describe_types
9999

100-
def __init__(self, **kwargs) -> None: # type: ignore[no-untyped-def]
100+
def __init__(self, force_timestamps: bool=False) -> None:
101101
"""Abstract class for all the MISP objects.
102102
NOTE: Every method in every classes inheriting this one are doing
103103
changes in memory and do not modify data on a remote MISP instance.
@@ -111,7 +111,7 @@ def __init__(self, **kwargs) -> None: # type: ignore[no-untyped-def]
111111
self.__self_defined_describe_types: dict[str, Any] | None = None
112112
self.uuid: str
113113

114-
if kwargs.get('force_timestamps') is not None:
114+
if force_timestamps:
115115
# Ignore the edited objects and keep the timestamps.
116116
self.__force_timestamps: bool = True
117117
else:
@@ -374,13 +374,16 @@ class MISPTag(AbstractMISP):
374374

375375
_fields_for_feed: set[str] = {'name', 'colour', 'relationship_type', 'local'}
376376

377-
def __init__(self, **kwargs) -> None: # type: ignore[no-untyped-def]
378-
super().__init__(**kwargs)
377+
def __init__(self, force_timestamps: bool=False, **kwargs) -> None: # type: ignore[no-untyped-def]
378+
super().__init__(force_timestamps)
379379
self.name: str
380380
self.exportable: bool
381381
self.local: bool
382382
self.relationship_type: str | None
383383

384+
if kwargs:
385+
self.from_dict(**kwargs)
386+
384387
def from_dict(self, **kwargs) -> None: # type: ignore[no-untyped-def]
385388
if kwargs.get('Tag'):
386389
kwargs = kwargs.get('Tag')

0 commit comments

Comments
 (0)