serenajiang commented on a change in pull request #16194:
URL: https://github.com/apache/superset/pull/16194#discussion_r687118410



##########
File path: superset/utils/core.py
##########
@@ -1273,7 +1280,33 @@ def is_adhoc_metric(metric: Metric) -> bool:
 
 
 def get_metric_name(metric: Metric) -> str:
-    return metric["label"] if is_adhoc_metric(metric) else metric  # type: 
ignore
+    """
+    Extract label from metric
+
+    :param metric: object to extract label from
+    :return: String representation of metric
+    :raises ValueError: if metric object is invalid
+    """
+    if is_adhoc_metric(metric):

Review comment:
       Could we make `is_adhoc_metric` a [type 
guard](https://www.python.org/dev/peps/pep-0647/) so that we don't need to use 
`cast` and `# type: ignore` so much? It's available in 
[typing_extensions](https://github.com/python/typing/blob/master/typing_extensions/README.rst).




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to