Skip to content

Commit

Permalink
annotate for py3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
babenek committed Nov 29, 2024
1 parent 2efcfeb commit 570f128
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions credsweeper/ml_model/features/word_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ def extract(self, candidate: Candidate) -> Any:

def word_in_str(self, a_string: str) -> np.ndarray:
"""Returns array with words included in a string"""
result = np.zeros(shape=[self.dimension], dtype=np.int8)
result:np.ndarray = np.zeros(shape=[self.dimension], dtype=np.int8)
for i, word in self.enumerated_words:
if word in a_string:
result[i] = 1
return np.array([result])

def word_in_set(self, a_strings_set: Set[str]) -> np.ndarray:
"""Returns array with words matches in a_strings_set"""
result = np.zeros(shape=[self.dimension], dtype=np.int8)
result:np.ndarray = np.zeros(shape=[self.dimension], dtype=np.int8)
for i, word in self.enumerated_words:
if word in a_strings_set:
result[i] = 1
Expand Down
12 changes: 6 additions & 6 deletions credsweeper/ml_model/ml_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import string
from pathlib import Path
from typing import List, Tuple, Union, Optional
from typing import List, Tuple, Union, Optional, Dict

import numpy as np
import onnxruntime as ort
Expand Down Expand Up @@ -90,7 +90,7 @@ def __init__(
@staticmethod
def encode(text: str, limit: int) -> np.ndarray:
"""Encodes prepared text to array"""
result_array = np.zeros(shape=(limit, MlValidator.NUM_CLASSES), dtype=np.float32)
result_array: np.ndarray = np.zeros(shape=(limit, MlValidator.NUM_CLASSES), dtype=np.float32)
if text is None:
return result_array
len_text = len(text)
Expand Down Expand Up @@ -122,7 +122,7 @@ def encode_value(text: str) -> np.ndarray:

def _call_model(self, line_input: np.ndarray, variable_input: np.ndarray, value_input: np.ndarray,
feature_input: np.ndarray) -> np.ndarray:
input_feed = {
input_feed: Dict[np.ndarray] = {
"line_input": line_input.astype(np.float32),
"variable_input": variable_input.astype(np.float32),
"value_input": value_input.astype(np.float32),
Expand All @@ -135,7 +135,7 @@ def _call_model(self, line_input: np.ndarray, variable_input: np.ndarray, value_

def extract_common_features(self, candidates: List[Candidate]) -> np.ndarray:
"""Extract features that are guaranteed to be the same for all candidates on the same line with same value."""
feature_array = np.array([], dtype=np.float32)
feature_array: np.ndarray = np.array([], dtype=np.float32)
# Extract features from credential candidate
default_candidate = candidates[0]
for feature in self.common_feature_list:
Expand All @@ -147,7 +147,7 @@ def extract_common_features(self, candidates: List[Candidate]) -> np.ndarray:

def extract_unique_features(self, candidates: List[Candidate]) -> np.ndarray:
"""Extract features that can be different between candidates. Join them with or operator."""
feature_array = np.array([], dtype=np.int8)
feature_array: np.ndarray = np.array([], dtype=np.int8)
default_candidate = candidates[0]
for feature in self.unique_feature_list:
new_feature = feature([default_candidate])[0]
Expand Down Expand Up @@ -220,7 +220,7 @@ def validate_groups(self, group_list: List[Tuple[CandidateKey, List[Candidate]]]
variable_input_list = []
value_input_list = []
features_list = []
probability = np.zeros(len(group_list), dtype=np.float32)
probability: np.ndarray = np.zeros(len(group_list), dtype=np.float32)
head = tail = 0
for group_key, candidates in group_list:
line_input, variable_input, value_input, feature_array = self.get_group_features(candidates)
Expand Down

0 comments on commit 570f128

Please sign in to comment.