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/rule_based_profiler/parameter_builder/numeric_metric_range_multi_batch_parameter_builder.py b/great_expectations/rule_based_profiler/parameter_builder/numeric_metric_range_multi_batch_parameter_builder.py
--- a/great_expectations/rule_based_profiler/parameter_builder/numeric_metric_range_multi_batch_parameter_builder.py
+++ b/great_expectations/rule_based_profiler/parameter_builder/numeric_metric_range_multi_batch_parameter_builder.py
@@ -232,21 +232,6 @@ def _build_parameters(
                 message=f"Utilizing a {self.__class__.__name__} requires a non-empty list of batch identifiers."
             )
 
-        metric_computation_result: MetricComputationResult = self.get_metrics(
-            batch_ids=batch_ids,
-            validator=validator,
-            metric_name=self._metric_name,
-            metric_domain_kwargs=self._metric_domain_kwargs,
-            metric_value_kwargs=self._metric_value_kwargs,
-            enforce_numeric_metric=self._enforce_numeric_metric,
-            replace_nan_with_zero=self._replace_nan_with_zero,
-            domain=domain,
-            variables=variables,
-            parameters=parameters,
-        )
-        metric_values: MetricComputationValues = metric_computation_result.metric_values
-        details: MetricComputationDetails = metric_computation_result.details
-
         # Obtain sampling_method directive from rule state (i.e., variables and parameters); from instance variable otherwise.
         sampling_method: str = get_parameter_value_and_validate_return_type(
             domain=domain,
@@ -280,6 +265,21 @@ def _build_parameters(
                 message=f"The confidence level for {self.__class__.__name__} is outside of [0.0, 1.0] closed interval."
             )
 
+        metric_computation_result: MetricComputationResult = self.get_metrics(
+            batch_ids=batch_ids,
+            validator=validator,
+            metric_name=self._metric_name,
+            metric_domain_kwargs=self._metric_domain_kwargs,
+            metric_value_kwargs=self._metric_value_kwargs,
+            enforce_numeric_metric=self._enforce_numeric_metric,
+            replace_nan_with_zero=self._replace_nan_with_zero,
+            domain=domain,
+            variables=variables,
+            parameters=parameters,
+        )
+        metric_values: MetricComputationValues = metric_computation_result.metric_values
+        details: MetricComputationDetails = metric_computation_result.details
+
         truncate_values: Dict[str, Number] = self._get_truncate_values_using_heuristics(
             metric_values=metric_values,
             domain=domain,
diff --git a/great_expectations/validator/validator.py b/great_expectations/validator/validator.py
--- a/great_expectations/validator/validator.py
+++ b/great_expectations/validator/validator.py
@@ -462,12 +462,11 @@ def graph_validate(
         else:
             catch_exceptions = False
 
-        graph: ValidationGraph
+        evrs: List[ExpectationValidationResult]
+
         expectation_validation_graphs: List[ExpectationValidationGraph] = []
-        exception_info: ExceptionInfo
-        processed_configurations: List[ExpectationConfiguration] = []
-        # noinspection SpellCheckingInspection
 
+        processed_configurations: List[ExpectationConfiguration] = []
         (
             evrs,
             processed_configurations,
@@ -479,13 +478,15 @@ def graph_validate(
             runtime_configuration=runtime_configuration,
         )
 
-        graph = self._generate_suite_level_graph_from_expectation_level_sub_graphs(
-            expectation_validation_graphs=expectation_validation_graphs
-        )
-
         if metrics is None:
             metrics = {}
 
+        graph: ValidationGraph = (
+            self._generate_suite_level_graph_from_expectation_level_sub_graphs(
+                expectation_validation_graphs=expectation_validation_graphs
+            )
+        )
+
         try:
             (
                 evrs,
@@ -498,12 +499,11 @@ def graph_validate(
                 evrs=evrs,
                 processed_configurations=processed_configurations,
             )
-
         except Exception as err:
             # If a general Exception occurs during the execution of "Validator.resolve_validation_graph()", then all
             # expectations in the suite are impacted, because it is impossible to attribute the failure to a metric.
             if catch_exceptions:
-                exception_traceback = traceback.format_exc()
+                exception_traceback: str = traceback.format_exc()
                 evrs = self._catch_exceptions_in_failing_expectation_validations(
                     exception_traceback=exception_traceback,
                     exception=err,
@@ -514,6 +514,8 @@ def graph_validate(
             else:
                 raise err
 
+        configuration: ExpectationConfiguration
+        result: ExpectationValidationResult
         for configuration in processed_configurations:
             try:
                 result = configuration.metrics_validate(
@@ -524,7 +526,7 @@ def graph_validate(
                 evrs.append(result)
             except Exception as err:
                 if catch_exceptions:
-                    exception_traceback = traceback.format_exc()
+                    exception_traceback: str = traceback.format_exc()
                     evrs = self._catch_exceptions_in_failing_expectation_validations(
                         exception_traceback=exception_traceback,
                         exception=err,
@@ -546,8 +548,11 @@ def _generate_metric_dependency_subgraphs_for_each_expectation_configuration(
     ) -> Tuple[List[ExpectationValidationResult], List[ExpectationConfiguration]]:
         # While evaluating expectation configurations, create sub-graph for every metric dependency and incorporate
         # these sub-graphs under corresponding expectation-level sub-graph (state of ExpectationValidationGraph object).
-
         evrs: List[ExpectationValidationResult] = []
+        configuration: ExpectationConfiguration
+        evaluated_config: ExpectationConfiguration
+        metric_configuration: MetricConfiguration
+        graph: ValidationGraph
         for configuration in expectation_configurations:
             # Validating
             try:
@@ -561,9 +566,11 @@ def _generate_metric_dependency_subgraphs_for_each_expectation_configuration(
             evaluated_config.kwargs.update({"batch_id": self.active_batch_id})
 
             expectation_impl = get_expectation_impl(evaluated_config.expectation_type)
-            validation_dependencies = expectation_impl().get_validation_dependencies(
-                evaluated_config, self._execution_engine, runtime_configuration
-            )["metrics"]
+            validation_dependencies: dict = (
+                expectation_impl().get_validation_dependencies(
+                    evaluated_config, self._execution_engine, runtime_configuration
+                )["metrics"]
+            )
 
             try:
                 expectation_validation_graph: ExpectationValidationGraph = (
@@ -583,13 +590,13 @@ def _generate_metric_dependency_subgraphs_for_each_expectation_configuration(
                 processed_configurations.append(evaluated_config)
             except Exception as err:
                 if catch_exceptions:
-                    exception_traceback = traceback.format_exc()
-                    exception_message = str(err)
-                    exception_info = ExceptionInfo(
+                    exception_traceback: str = traceback.format_exc()
+                    exception_message: str = str(err)
+                    exception_info: ExceptionInfo = ExceptionInfo(
                         exception_traceback=exception_traceback,
                         exception_message=exception_message,
                     )
-                    result = ExpectationValidationResult(
+                    result: ExpectationValidationResult = ExpectationValidationResult(
                         success=False,
                         exception_info=exception_info,
                         expectation_config=evaluated_config,
@@ -614,7 +621,7 @@ def _generate_suite_level_graph_from_expectation_level_sub_graphs(
                 ]
             )
         )
-        validation_graph = ValidationGraph(edges=edges)
+        validation_graph: ValidationGraph = ValidationGraph(edges=edges)
         return validation_graph
 
     def _resolve_suite_level_graph_and_process_metric_evaluation_errors(
@@ -664,9 +671,9 @@ def _resolve_suite_level_graph_and_process_metric_evaluation_errors(
 
         return evrs, processed_configurations
 
+    @staticmethod
     def _catch_exceptions_in_failing_expectation_validations(
-        self,
-        exception_traceback: traceback.TracebackException,
+        exception_traceback: str,
         exception: Exception,
         failing_expectation_configurations: List[ExpectationConfiguration],
         evrs: List[ExpectationValidationResult],
@@ -682,12 +689,14 @@ def _catch_exceptions_in_failing_expectation_validations(
         Returns:
             List of ExpectationValidationResult objects with unsuccessful ExpectationValidationResult objects appended
         """
-        exception_message = str(exception)
-        exception_info = ExceptionInfo(
+        exception_message: str = str(exception)
+        exception_info: ExceptionInfo = ExceptionInfo(
             exception_traceback=exception_traceback,
             exception_message=exception_message,
         )
 
+        configuration: ExpectationConfiguration
+        result: ExpectationValidationResult
         for configuration in failing_expectation_configurations:
             result = ExpectationValidationResult(
                 success=False,


Test patch: