Skip to content

Commit 0c6ed39

Browse files
author
Dan Hertz
committed
add optional type hints
1 parent e9daba1 commit 0c6ed39

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

nightfall/api.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import json
1111
import logging
1212
import os
13-
from typing import List, Tuple
13+
from typing import List, Tuple, Optional
1414

1515
import requests
1616

@@ -27,7 +27,7 @@ class Nightfall:
2727
FILE_SCAN_COMPLETE_ENDPOINT = PLATFORM_URL + "/v3/upload/{0}/finish"
2828
FILE_SCAN_SCAN_ENDPOINT = PLATFORM_URL + "/v3/upload/{0}/scan"
2929

30-
def __init__(self, key: str = None, signing_secret: str = None):
30+
def __init__(self, key: Optional[str] = None, signing_secret: Optional[str] = None):
3131
"""Instantiate a new Nightfall object.
3232
:param key: Your Nightfall API key. If None it will be read from the environment variable NIGHTFALL_API_KEY.
3333
:type key: str or None
@@ -51,8 +51,8 @@ def __init__(self, key: str = None, signing_secret: str = None):
5151
self.signing_secret = signing_secret
5252
self.logger = logging.getLogger(__name__)
5353

54-
def scan_text(self, texts: List[str], detection_rules: List[DetectionRule] = None,
55-
detection_rule_uuids: List[str] = None) -> Tuple[List[List[Finding]], List[str]]:
54+
def scan_text(self, texts: List[str], detection_rules: Optional[List[DetectionRule]] = None,
55+
detection_rule_uuids: Optional[List[str]] = None) -> Tuple[List[List[Finding]], List[str]]:
5656
"""Scan text with Nightfall.
5757
5858
This method takes the specified config and then makes
@@ -111,9 +111,9 @@ def _scan_text_v3(self, data: dict):
111111

112112
# File Scan
113113

114-
def scan_file(self, location: str, webhook_url: str = None, policy_uuid: str = None,
115-
detection_rules: List[DetectionRule] = None, detection_rule_uuids: List[str] = None,
116-
) -> Tuple[str, str]:
114+
def scan_file(self, location: str, webhook_url: Optional[str] = None, policy_uuid: Optional[str] = None,
115+
detection_rules: Optional[List[DetectionRule]] = None,
116+
detection_rule_uuids: Optional[List[str]] = None) -> Tuple[str, str]:
117117
"""Scan file with Nightfall.
118118
At least one of policy_uuid, detection_rule_uuids or detection_rules is required.
119119
@@ -200,8 +200,9 @@ def _file_scan_finalize(self, session_id: str):
200200
)
201201
return response
202202

203-
def _file_scan_scan(self, session_id: str, detection_rules: List[DetectionRule] = None,
204-
detection_rule_uuids: List[str] = None, webhook_url: str = None, policy_uuid: str = None):
203+
def _file_scan_scan(self, session_id: str, detection_rules: Optional[List[DetectionRule]] = None,
204+
detection_rule_uuids: Optional[List[str]] = None, webhook_url: Optional[str] = None,
205+
policy_uuid: Optional[str] = None) -> requests.Response:
205206
if policy_uuid:
206207
data = {"policyUUID": policy_uuid}
207208
else:

nightfall/detection_rules.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dataclasses import dataclass, field
22
from enum import Enum
3-
from typing import List
3+
from typing import List, Optional
44

55
from nightfall.exceptions import NightfallUserError
66

@@ -81,8 +81,8 @@ class ExclusionRule:
8181
word_list (WordList or None): The list of words to compare to a candidate finding.
8282
"""
8383
match_type: MatchType
84-
regex: Regex = None
85-
word_list: WordList = None
84+
regex: Optional[Regex] = None
85+
word_list: Optional[WordList] = None
8686

8787
def __post_init__(self):
8888
if (not self.regex and not self.word_list) or (self.regex and self.word_list):
@@ -137,15 +137,15 @@ class RedactionConfig:
137137
Attributes:
138138
remove_finding (bool): Whether the original finding should be omitted in responses from the API.
139139
mask_config (MaskConfig): Build a redaction config with masking.
140-
substitution_phrase (str or None): Build a redaction config with info type substitution.
140+
substitution_phrase (str or None): Build a redaction config with a substitution phrase.
141141
infotype_substitution (bool or None): Build a redaction config with info type substitution.
142142
public_key (str or None): Build a redaction config with RSA encryption.
143143
"""
144144
remove_finding: bool
145-
mask_config: MaskConfig = None
146-
substitution_phrase: str = None
145+
mask_config: Optional[MaskConfig] = None
146+
substitution_phrase: Optional[str] = None
147147
infotype_substitution: bool = False
148-
public_key: str = None
148+
public_key: Optional[str] = None
149149

150150
def __post_init__(self):
151151
config_counts = [self.mask_config, self.substitution_phrase, self.public_key].count(None)
@@ -187,14 +187,14 @@ class Detector:
187187
"""
188188
min_confidence: Confidence
189189
min_num_findings: int = 1
190-
nightfall_detector: str = None
191-
regex: Regex = None
192-
word_list: WordList = None
193-
uuid: str = None
194-
display_name: str = None
195-
context_rules: List[ContextRule] = None
196-
exclusion_rules: List[ExclusionRule] = None
197-
redaction_config: RedactionConfig = None
190+
nightfall_detector: Optional[str] = None
191+
regex: Optional[Regex] = None
192+
word_list: Optional[WordList] = None
193+
uuid: Optional[str] = None
194+
display_name: Optional[str] = None
195+
context_rules: Optional[List[ContextRule]] = None
196+
exclusion_rules: Optional[List[ExclusionRule]] = None
197+
redaction_config: Optional[RedactionConfig] = None
198198

199199
def __post_init__(self):
200200
if [self.nightfall_detector, self.regex, self.word_list, self.uuid].count(None) != 3:

0 commit comments

Comments
 (0)