Merge pull request #5 from dfn-certling/cluster-search-typing

Cluster search typing
pull/7/head
Raphaël Vinot 2021-11-05 15:17:13 -07:00 committed by GitHub
commit f91c455cc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -8,7 +8,12 @@ import sys
from collections.abc import Mapping
from glob import glob
import re
from typing import List, Dict, Optional, Any, Tuple, Iterator
from typing import List, Dict, Optional, Any, Tuple, Iterator, overload, Union
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
try:
import jsonschema # type: ignore
@ -225,7 +230,14 @@ class Cluster(Mapping): # type: ignore
raise PyMISPGalaxiesError("Duplicate value ({}) in cluster: {}".format(new_cluster_value.value, self.name))
self.cluster_values[new_cluster_value.value] = new_cluster_value
def search(self, query: str, return_tags: bool=False) -> List[str]:
@overload
def search(self, query: str, return_tags: Literal[False]=False) -> List[ClusterValue]: ...
@overload
def search(self, query: str, return_tags: Literal[True]) -> List[str]: ...
@overload
def search(self, query: str, return_tags: bool) -> Union[List[ClusterValue], List[str]]: ...
def search(self, query: str, return_tags: bool=False) -> Union[List[ClusterValue], List[str]]:
matching = []
for v in self.values():
if [s for s in v.searchable if query.lower() in s.lower()]: