gemini-code-assist[bot] commented on code in PR #37566:
URL: https://github.com/apache/beam/pull/37566#discussion_r2794109302
##########
sdks/python/apache_beam/coders/coders.py:
##########
@@ -1005,20 +1005,11 @@ def to_type_hint(self):
return Any
-def _should_force_use_dill(registry):
- # force_dill_deterministic_coders is for testing purposes. If there is a
- # DeterministicFastPrimitivesCoder in the pipeline graph but the dill
- # encoding path is not really triggered dill does not have to be installed.
- # and this check can be skipped.
- if getattr(registry, 'force_dill_deterministic_coders', False):
- return True
+def _should_force_use_dill():
+ from apache_beam.options.pipeline_options_context import get_pipeline_options
Review Comment:

Similar to the previous comment, placing imports inside a function can lead
to repeated imports if the function is called multiple times. For better
practice and potential efficiency gains, move this import to the top of the
file.
```python
from apache_beam.options.pipeline_options_context import get_pipeline_options
```
##########
sdks/python/apache_beam/coders/coders.py:
##########
@@ -927,16 +927,16 @@ def _create_impl(self):
class DeterministicFastPrimitivesCoderV2(FastCoder):
"""Throws runtime errors when encoding non-deterministic values."""
- def __init__(self, coder, step_label, update_compatibility_version=None):
+ def __init__(self, coder, step_label):
self._underlying_coder = coder
self._step_label = step_label
self._use_relative_filepaths = True
self._version_tag = "v2_69"
- from apache_beam.transforms.util import is_v1_prior_to_v2
# Versions prior to 2.69.0 did not use relative filepaths.
- if update_compatibility_version and is_v1_prior_to_v2(
- v1=update_compatibility_version, v2="2.69.0"):
+ from apache_beam.options.pipeline_options_context import
get_pipeline_options
Review Comment:

It is generally recommended to place all imports at the top of the file,
rather than inside methods or functions. This improves readability and avoids
potential performance overhead from repeated imports, especially if the
`__init__` method is called frequently. Consider moving this import to the top
of the file.
```python
from apache_beam.options.pipeline_options_context import get_pipeline_options
```
--
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]