Repository: great-expectations/great_expectations

Issue:
Use cleaner solution for non-truncating division in python 2
Prefer `from __future__ import division` to `1.*x/y`


Discussion:
Done inline during improve_partitions push.

Resolving patch:
diff --git a/great_expectations/core/usage_statistics/anonymizers/anonymizer.py b/great_expectations/core/usage_statistics/anonymizers/anonymizer.py
--- a/great_expectations/core/usage_statistics/anonymizers/anonymizer.py
+++ b/great_expectations/core/usage_statistics/anonymizers/anonymizer.py
@@ -26,6 +26,15 @@ def salt(self):
         return self._salt
 
     def anonymize(self, string_):
+        if string_ is None:
+            return None
+
+        if not isinstance(string_, str):
+            raise TypeError(
+                f"""The type of the "string_" argument must be a string (Python "str").  The type given is
+"{str(type(string_))}", which is illegal.
+            """
+            )
         salted = self._salt + string_
         return md5(salted.encode("utf-8")).hexdigest()
 
diff --git a/great_expectations/core/usage_statistics/anonymizers/batch_request_anonymizer.py b/great_expectations/core/usage_statistics/anonymizers/batch_request_anonymizer.py
--- a/great_expectations/core/usage_statistics/anonymizers/batch_request_anonymizer.py
+++ b/great_expectations/core/usage_statistics/anonymizers/batch_request_anonymizer.py
@@ -1,4 +1,5 @@
 import copy
+import logging
 from typing import Any, Dict, List, Optional, Set, Union
 
 from great_expectations.core.batch import (
@@ -21,6 +22,8 @@
     BATCH_REQUEST_FLATTENED_KEYS,
 )
 
+logger = logging.getLogger(__name__)
+
 
 class BatchRequestAnonymizer(Anonymizer):
     def __init__(self, salt=None):
@@ -32,39 +35,52 @@ def __init__(self, salt=None):
         self._data_connector_query_keys = []
         self._runtime_parameters_keys = []
 
-    def anonymize_batch_request(self, *args, **kwargs) -> Dict[str, List[str]]:
-        batch_request: Union[
-            BatchRequest
-        ] = get_batch_request_from_acceptable_arguments(*args, **kwargs)
-        batch_request_dict: dict = batch_request.to_json_dict()
-        anonymized_batch_request_dict: Optional[
-            Union[str, dict]
-        ] = self._anonymize_batch_request_properties(source=batch_request_dict)
-        anonymized_batch_request_dict = standardize_batch_request_display_ordering(
-            batch_request=anonymized_batch_request_dict
-        )
-        deep_filter_properties_iterable(
-            properties=anonymized_batch_request_dict,
-            clean_falsy=True,
-            inplace=True,
-        )
-        anonymized_batch_request_properties_dict: Dict[str, List[str]] = {
-            "anonymized_batch_request_required_top_level_properties": self._anonymized_batch_request_required_top_level_properties,
-            "batch_request_optional_top_level_keys": self._batch_request_optional_top_level_keys,
-            "batch_spec_passthrough_keys": self._batch_spec_passthrough_keys,
-            "runtime_parameters_keys": self._runtime_parameters_keys,
-            "data_connector_query_keys": self._data_connector_query_keys,
-        }
-        self._build_anonymized_batch_request(source=anonymized_batch_request_dict)
-        deep_filter_properties_iterable(
-            properties=anonymized_batch_request_properties_dict,
-            clean_falsy=True,
-            inplace=True,
-        )
-        self._batch_request_optional_top_level_keys.sort()
-        self._batch_spec_passthrough_keys.sort()
-        self._data_connector_query_keys.sort()
-        self._runtime_parameters_keys.sort()
+    def anonymize_batch_request(
+        self, *args, **kwargs
+    ) -> Optional[Dict[str, List[str]]]:
+        anonymized_batch_request_properties_dict: Optional[Dict[str, List[str]]] = None
+
+        # noinspection PyBroadException
+        try:
+            batch_request: Union[
+                BatchRequest
+            ] = get_batch_request_from_acceptable_arguments(*args, **kwargs)
+            batch_request_dict: dict = batch_request.to_json_dict()
+
+            anonymized_batch_request_dict: Optional[
+                Union[str, dict]
+            ] = self._anonymize_batch_request_properties(source=batch_request_dict)
+            anonymized_batch_request_dict = standardize_batch_request_display_ordering(
+                batch_request=anonymized_batch_request_dict
+            )
+            deep_filter_properties_iterable(
+                properties=anonymized_batch_request_dict,
+                clean_falsy=True,
+                inplace=True,
+            )
+            anonymized_batch_request_properties_dict = {
+                "anonymized_batch_request_required_top_level_properties": self._anonymized_batch_request_required_top_level_properties,
+                "batch_request_optional_top_level_keys": self._batch_request_optional_top_level_keys,
+                "batch_spec_passthrough_keys": self._batch_spec_passthrough_keys,
+                "runtime_parameters_keys": self._runtime_parameters_keys,
+                "data_connector_query_keys": self._data_connector_query_keys,
+            }
+            self._build_anonymized_batch_request(source=anonymized_batch_request_dict)
+            deep_filter_properties_iterable(
+                properties=anonymized_batch_request_properties_dict,
+                clean_falsy=True,
+                inplace=True,
+            )
+            self._batch_request_optional_top_level_keys.sort()
+            self._batch_spec_passthrough_keys.sort()
+            self._data_connector_query_keys.sort()
+            self._runtime_parameters_keys.sort()
+
+        except Exception:
+            logger.debug(
+                "anonymize_batch_request: Unable to create anonymized_batch_request payload field"
+            )
+
         return anonymized_batch_request_properties_dict
 
     def _anonymize_batch_request_properties(
diff --git a/great_expectations/core/usage_statistics/anonymizers/checkpoint_run_anonymizer.py b/great_expectations/core/usage_statistics/anonymizers/checkpoint_run_anonymizer.py
--- a/great_expectations/core/usage_statistics/anonymizers/checkpoint_run_anonymizer.py
+++ b/great_expectations/core/usage_statistics/anonymizers/checkpoint_run_anonymizer.py
@@ -51,11 +51,7 @@ def anonymize_checkpoint_run(self, *args, **kwargs) -> Dict[str, List[str]]:
         checkpoint_optional_top_level_keys: List[str] = []
 
         name: Optional[str] = kwargs.get("name")
-        anonymized_name: Optional[str]
-        if name is None:
-            anonymized_name = None
-        else:
-            anonymized_name = self.anonymize(name)
+        anonymized_name: Optional[str] = self.anonymize(name)
 
         config_version: Optional[Number] = kwargs.get("config_version")
         config_version: Optional[str]
@@ -63,44 +59,23 @@ def anonymize_checkpoint_run(self, *args, **kwargs) -> Dict[str, List[str]]:
             config_version = 1
 
         template_name: Optional[str] = kwargs.get("template_name")
-        anonymized_template_name: Optional[str]
-        if template_name is None:
-            anonymized_template_name = None
-        else:
-            anonymized_template_name = self.anonymize(template_name)
+        anonymized_template_name: Optional[str] = self.anonymize(template_name)
 
         run_name_template: Optional[str] = kwargs.get("run_name_template")
-        anonymized_run_name_template: Optional[str]
-        if run_name_template is None:
-            anonymized_run_name_template = None
-        else:
-            anonymized_run_name_template = self.anonymize(run_name_template)
+        anonymized_run_name_template: Optional[str] = self.anonymize(run_name_template)
 
         expectation_suite_name: Optional[str] = kwargs.get("expectation_suite_name")
-        anonymized_expectation_suite_name: Optional[str]
-        if expectation_suite_name is None:
-            anonymized_expectation_suite_name = None
-        else:
-            anonymized_expectation_suite_name = self.anonymize(expectation_suite_name)
+        anonymized_expectation_suite_name: Optional[str] = self.anonymize(
+            expectation_suite_name
+        )
 
         batch_request: Optional[Union[BatchRequest, dict]] = kwargs.get("batch_request")
         if batch_request is None:
             batch_request = {}
 
-        anonymized_batch_request: Optional[Dict[str, List[str]]] = None
-
-        if batch_request:
-            # noinspection PyBroadException
-            try:
-                anonymized_batch_request = (
-                    batch_request_anonymizer.anonymize_batch_request(
-                        *(), **batch_request
-                    )
-                )
-            except Exception:
-                logger.debug(
-                    "anonymize_checkpoint_run: Unable to create anonymized_batch_request payload field"
-                )
+        anonymized_batch_request: Optional[
+            Dict[str, List[str]]
+        ] = batch_request_anonymizer.anonymize_batch_request(*(), **batch_request)
 
         action_list: Optional[List[dict]] = kwargs.get("action_list")
         anonymized_action_list: Optional[List[dict]] = None
@@ -113,7 +88,6 @@ def anonymize_checkpoint_run(self, *args, **kwargs) -> Dict[str, List[str]]:
                         action_config=action_config_dict["action"],
                     )
                     for action_config_dict in action_list
-                    # for action_name, action_obj in action_config_dict.items()
                 ]
             except Exception:
                 logger.debug(
@@ -134,31 +108,17 @@ def anonymize_checkpoint_run(self, *args, **kwargs) -> Dict[str, List[str]]:
                     validation_batch_request = validation_batch_request.to_dict()
 
                 anonymized_validation_batch_request: Optional[
-                    Dict[str, List[str]]
-                ] = None
-                if validation_batch_request:
-                    # noinspection PyBroadException
-                    try:
-                        anonymized_validation_batch_request = (
-                            batch_request_anonymizer.anonymize_batch_request(
-                                *(), **validation_batch_request
-                            )
-                        )
-                    except Exception:
-                        logger.debug(
-                            "anonymize_checkpoint_run: Unable to create anonymized_batch_request payload field"
-                        )
+                    Optional[Dict[str, List[str]]]
+                ] = batch_request_anonymizer.anonymize_batch_request(
+                    *(), **validation_batch_request
+                )
 
                 validation_expectation_suite_name: Optional[str] = validation_obj.get(
                     "expectation_suite_name"
                 )
-                anonymized_validation_expectation_suite_name: Optional[str]
-                if validation_expectation_suite_name is None:
-                    anonymized_validation_expectation_suite_name = None
-                else:
-                    anonymized_validation_expectation_suite_name = self.anonymize(
-                        validation_expectation_suite_name
-                    )
+                anonymized_validation_expectation_suite_name: Optional[
+                    str
+                ] = self.anonymize(validation_expectation_suite_name)
 
                 validation_action_list: Optional[List[dict]] = validation_obj.get(
                     "action_list"


Test patch: