diff --git a/presidio-structured/presidio_structured/analysis_builder.py b/presidio-structured/presidio_structured/analysis_builder.py index b2db7ef6f..872be127c 100644 --- a/presidio-structured/presidio_structured/analysis_builder.py +++ b/presidio-structured/presidio_structured/analysis_builder.py @@ -56,8 +56,8 @@ def generate_analysis( def _remove_low_scores( self, key_recognizer_result_map: Dict[str, RecognizerResult], - score_threshold: float = None, - ) -> List[RecognizerResult]: + score_threshold: Optional[float] = None, + ) -> Dict[str, RecognizerResult]: """ Remove results for which the confidence is lower than the threshold. @@ -127,13 +127,15 @@ def _generate_analysis_from_results_json( for result in analyzer_results: current_key = prefix + result.key - if isinstance(result.value, dict): + if isinstance(result.value, dict) and isinstance( + result.recognizer_results, Iterator + ): nested_mappings = self._generate_analysis_from_results_json( result.recognizer_results, prefix=current_key + "." ) key_recognizer_result_map.update(nested_mappings) first_recognizer_result = next(iter(result.recognizer_results), None) - if first_recognizer_result is not None: + if isinstance(first_recognizer_result, RecognizerResult): logger.debug( f"Found result with entity {first_recognizer_result.entity_type} \ in {current_key}" diff --git a/presidio-structured/presidio_structured/data/data_processors.py b/presidio-structured/presidio_structured/data/data_processors.py index 4e09d1cd9..4ee3eb41b 100644 --- a/presidio-structured/presidio_structured/data/data_processors.py +++ b/presidio-structured/presidio_structured/data/data_processors.py @@ -134,7 +134,7 @@ class JsonDataProcessor(DataProcessorBase): """JSON Data Processor, Supports arbitrary nesting of dictionaries and lists.""" @staticmethod - def _get_nested_value(data: Union[Dict, List], path: List[str]) -> Any: + def _get_nested_value(data: Union[Dict, List, None], path: List[str]) -> Any: """ Recursively retrieves the value from nested data using a given path. diff --git a/presidio-structured/presidio_structured/structured_engine.py b/presidio-structured/presidio_structured/structured_engine.py index e36dc86fb..22a379ed6 100644 --- a/presidio-structured/presidio_structured/structured_engine.py +++ b/presidio-structured/presidio_structured/structured_engine.py @@ -33,7 +33,7 @@ def anonymize( self, data: Union[Dict, DataFrame], structured_analysis: StructuredAnalysis, - operators: Dict[str, OperatorConfig] = None, + operators: Union[Dict[str, OperatorConfig], None] = None, ) -> Union[Dict, DataFrame]: """ Anonymize the given data using the given configuration. @@ -49,7 +49,7 @@ def anonymize( return self.data_processor.operate(data, structured_analysis, operators) def __check_or_add_default_operator( - self, operators: Dict[str, OperatorConfig] + self, operators: Union[Dict[str, OperatorConfig], None] ) -> Dict[str, OperatorConfig]: """ Check if the provided operators dictionary has a default operator. \