fix: mypy, more typing

pull/551/head
Raphaël Vinot 2020-02-24 17:09:42 +01:00
parent 94c2a644af
commit 8d6e69ce65
2 changed files with 9 additions and 10 deletions

View File

@ -249,7 +249,7 @@ class AbstractMISP(MutableMapping, MISPFileCache, metaclass=ABCMeta):
def __iter__(self):
return iter({k: v for k, v in self.__dict__.items() if not (k[0] == '_' or k in self.__not_jsonable)})
def __len__(self):
def __len__(self) -> int:
return len([k for k in self.__dict__.keys() if not (k[0] == '_' or k in self.__not_jsonable)])
@property
@ -269,15 +269,15 @@ class AbstractMISP(MutableMapping, MISPFileCache, metaclass=ABCMeta):
return self.__edited
@edited.setter
def edited(self, val):
def edited(self, val: bool):
"""Set the edit flag"""
if isinstance(val, bool):
self.__edited = val
else:
raise PyMISPError('edited can only be True or False')
def __setattr__(self, name, value):
if name[0] != '_' and not self.__edited and name in self.keys():
def __setattr__(self, name: str, value):
if name[0] != '_' and not self.__edited and name in self:
# The private members don't matter
# If we already have a key with that name, we're modifying it.
self.__edited = True
@ -317,7 +317,7 @@ class AbstractMISP(MutableMapping, MISPFileCache, metaclass=ABCMeta):
else:
raise PyMISPInvalidFormat('All the attributes have to be of type MISPTag.')
def __eq__(self, other):
def __eq__(self, other) -> bool:
if isinstance(other, AbstractMISP):
return self.to_dict() == other.to_dict()
elif isinstance(other, dict):
@ -325,10 +325,8 @@ class AbstractMISP(MutableMapping, MISPFileCache, metaclass=ABCMeta):
else:
return False
def __repr__(self):
if hasattr(self, 'name'):
return '<{self.__class__.__name__}(name={self.name})'.format(self=self)
return '<{self.__class__.__name__}(NotInitialized)'.format(self=self)
def __repr__(self) -> str:
return '<{self.__class__.__name__} - please define me'.format(self=self)
class MISPTag(AbstractMISP):

View File

@ -224,7 +224,8 @@ class MISPAttribute(AbstractMISP):
if self.type == 'malware-sample':
try:
with ZipFile(self.data) as f:
# Ignore type, if data is None -> exception
with ZipFile(self.data) as f: # type: ignore
if not self.__is_misp_encrypted_file(f):
raise PyMISPError('Not an existing malware sample')
for name in f.namelist():