gemini-code-assist[bot] commented on code in PR #37522:
URL: https://github.com/apache/beam/pull/37522#discussion_r2770373656


##########
sdks/python/apache_beam/pipeline.py:
##########
@@ -698,6 +705,15 @@ def apply(
       RuntimeError: if the transform object was already applied to
         this pipeline and needs to be cloned in order to apply again.
     """
+    with scoped_pipeline_options(self._options):
+      return self._apply_internal(transform, pvalueish, label)
+
+  def _apply_internal(
+      self,
+      transform: ptransform.PTransform,
+      pvalueish: Optional[pvalue.PValue] = None,
+      label: Optional[str] = None) -> pvalue.PValue:
+    """Internal implementation of apply(), called within scoped options."""
     if isinstance(transform, ptransform._NamedPTransform):
       return self.apply(
           transform.transform, pvalueish, label or transform.label)

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The recursive call to `self.apply` will re-enter the 
`scoped_pipeline_options` context manager, which is inefficient. Since the 
context is already established by the public `apply` method, this internal 
method should call `self._apply_internal` recursively to avoid nesting context 
managers.
   
   ```suggestion
         return self._apply_internal(
             transform.transform, pvalueish, label or transform.label)
   ```



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