gemini-code-assist[bot] commented on code in PR #35745:
URL: https://github.com/apache/beam/pull/35745#discussion_r2243903937
##########
sdks/python/apache_beam/yaml/yaml_ml.py:
##########
@@ -50,11 +50,11 @@ def _list_submodules(package):
from apache_beam.ml.transforms import tft
from apache_beam.ml.transforms.base import MLTransform
# TODO(robertwb): Is this all of them?
- _transform_constructors = {}
except ImportError:
tft = None # type: ignore
Review Comment:

While this change correctly fixes the `NameError` for
`_transform_constructors`, a similar issue exists for `MLTransform`. If `from
apache_beam.ml.transforms.base import MLTransform` fails, `MLTransform` will be
undefined, causing a `NameError` later in the loop when `issubclass(cls,
MLTransform)` is called.
To make this more robust, you should also handle the case where
`MLTransform` is not imported. A simple way is to define a dummy class in the
`except` block. This would prevent the `NameError` and cause `issubclass` to
correctly return `False` for any transform.
```suggestion
except ImportError:
tft = None # type: ignore
MLTransform = type('MLTransform', (), {}) # Dummy class if import fails
```
--
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]