shunping commented on code in PR #33845:
URL: https://github.com/apache/beam/pull/33845#discussion_r1946865448


##########
sdks/python/apache_beam/ml/anomaly/specifiable.py:
##########
@@ -30,67 +34,119 @@
 
 from typing_extensions import Self
 
+__all__ = ["KNOWN_SPECIFIABLE", "Spec", "Specifiable", "specifiable"]
+
 ACCEPTED_SPECIFIABLE_SUBSPACES = [
     "EnsembleAnomalyDetector",
     "AnomalyDetector",
     "ThresholdFn",
     "AggregationFn",
     "*"
 ]
+
+#: A nested dictionary for efficient lookup of Specifiable subclasses.
+#: Structure: KNOWN_SPECIFIABLE[subspace][spec_type], where "subspace" is one 
of
+#: the accepted subspaces that the class belongs to and "spec_type" is the 
class
+#: name by default. Users can also specify a different value for "spec_type"
+#: when applying the `specifiable` decorator to an existing class.
 KNOWN_SPECIFIABLE = {"*": {}}
 
 SpecT = TypeVar('SpecT', bound='Specifiable')
 
 
-def get_subspace(cls, type=None):
-  if type is None:
-    subspace = "*"
-    for c in cls.mro():
-      if c.__name__ in ACCEPTED_SPECIFIABLE_SUBSPACES:
-        subspace = c.__name__
-        break
-    return subspace
-  else:
-    for subspace in ACCEPTED_SPECIFIABLE_SUBSPACES:
-      if subspace in KNOWN_SPECIFIABLE and type in KNOWN_SPECIFIABLE[subspace]:
-        return subspace
+def _class_to_subspace(cls: Type, default="*") -> str:
+  """
+  Search the class hierarchy to find the subspace: the closest ancestor class 
in
+  the class's method resolution order (MRO) whose name is found in the accepted
+  subspace list. This is usually called when registering a new Specifiable
+  class.
+  """
+  for c in cls.mro():
+    #
+    if c.__name__ in ACCEPTED_SPECIFIABLE_SUBSPACES:
+      return c.__name__
+
+  if default is None:

Review Comment:
   You are right. The code right now always use "*" as the default. 
   
   However, since subspace "*" is only used in testing, I am thinking about 
removing it from the ACCEPTED_SPECIFIABLE_SUBSPACES. In this case, we will only 
support making certain types of classes into specifiable.



-- 
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]

Reply via email to