fix: Typing on recent mypy

pull/665/head
Raphaël Vinot 2020-11-25 13:19:19 +01:00
parent d06313a653
commit f254e15bd4
2 changed files with 8 additions and 7 deletions

View File

@ -60,9 +60,10 @@ def get_uuid_or_id_from_abstract_misp(obj: Union[AbstractMISP, int, str, UUID])
if isinstance(obj, MISPOrganisationBlocklist): if isinstance(obj, MISPOrganisationBlocklist):
return obj.org_uuid return obj.org_uuid
if 'uuid' in obj: # at this point, we must have an AbstractMISP
return obj['uuid'] if 'uuid' in obj: # type: ignore
return obj['id'] return obj['uuid'] # type: ignore
return obj['id'] # type: ignore
def register_user(misp_url: str, email: str, def register_user(misp_url: str, email: str,

View File

@ -6,7 +6,7 @@ import json
import os import os
import base64 import base64
import sys import sys
from io import BytesIO, IOBase from io import BytesIO, RawIOBase
from zipfile import ZipFile from zipfile import ZipFile
import uuid import uuid
from collections import defaultdict from collections import defaultdict
@ -1150,9 +1150,9 @@ class MISPEvent(AbstractMISP):
def load(self, json_event: Union[IO, str, bytes, dict], validate: bool = False, metadata_only: bool = False): def load(self, json_event: Union[IO, str, bytes, dict], validate: bool = False, metadata_only: bool = False):
"""Load a JSON dump from a pseudo file or a JSON string""" """Load a JSON dump from a pseudo file or a JSON string"""
if isinstance(json_event, IOBase): if isinstance(json_event, RawIOBase):
# python2 and python3 compatible to find if we have a file json_event = json_event.read() # type: ignore
json_event = json_event.read()
if isinstance(json_event, (str, bytes)): if isinstance(json_event, (str, bytes)):
json_event = json.loads(json_event) json_event = json.loads(json_event)