File tree Expand file tree Collapse file tree 4 files changed +44
-28
lines changed
sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding Expand file tree Collapse file tree 4 files changed +44
-28
lines changed Original file line number Diff line number Diff line change @@ -217,13 +217,8 @@ def begin_analyze( # type: ignore[override] # pyright: ignore[reportIncompatib
217217 ** kwargs ,
218218 )
219219
220- # Wrap in custom poller with .operation_id property
221- return AnalyzeLROPoller ( # pyright: ignore[reportInvalidTypeArguments]
222- self ._client ,
223- poller ._polling_method ._initial_response , # type: ignore # pylint: disable=protected-access
224- poller ._polling_method ._deserialization_callback , # type: ignore # pylint: disable=protected-access
225- poller ._polling_method , # pylint: disable=protected-access
226- )
220+ # Wrap in custom poller with .operation_id property (without re-initializing)
221+ return AnalyzeLROPoller .from_poller (poller ) # pyright: ignore[reportReturnType]
227222
228223 @distributed_trace
229224 def begin_analyze_binary (
@@ -274,13 +269,8 @@ def begin_analyze_binary(
274269 ** kwargs ,
275270 )
276271
277- # Wrap in custom poller with .operation_id property
278- return AnalyzeLROPoller ( # pyright: ignore[reportInvalidTypeArguments]
279- self ._client ,
280- poller ._polling_method ._initial_response , # type: ignore # pylint: disable=protected-access
281- poller ._polling_method ._deserialization_callback , # type: ignore # pylint: disable=protected-access
282- poller ._polling_method , # pylint: disable=protected-access
283- )
272+ # Wrap in custom poller with .operation_id property (without re-initializing)
273+ return AnalyzeLROPoller .from_poller (poller ) # pyright: ignore[reportReturnType]
284274
285275
286276def patch_sdk ():
Original file line number Diff line number Diff line change @@ -217,13 +217,8 @@ async def begin_analyze( # type: ignore[override] # pyright: ignore[reportInco
217217 ** kwargs ,
218218 )
219219
220- # Wrap in custom poller with .operation_id property
221- return AnalyzeAsyncLROPoller ( # pyright: ignore[reportInvalidTypeArguments]
222- self ._client ,
223- poller ._polling_method ._initial_response , # type: ignore # pylint: disable=protected-access
224- poller ._polling_method ._deserialization_callback , # type: ignore # pylint: disable=protected-access
225- poller ._polling_method , # pylint: disable=protected-access
226- )
220+ # Wrap in custom poller with .operation_id property (without re-initializing)
221+ return AnalyzeAsyncLROPoller .from_poller (poller ) # pyright: ignore[reportReturnType]
227222
228223 @distributed_trace_async
229224 async def begin_analyze_binary (
@@ -274,13 +269,8 @@ async def begin_analyze_binary(
274269 ** kwargs ,
275270 )
276271
277- # Wrap in custom poller with .operation_id property
278- return AnalyzeAsyncLROPoller ( # pyright: ignore[reportInvalidTypeArguments]
279- self ._client ,
280- poller ._polling_method ._initial_response , # type: ignore # pylint: disable=protected-access
281- poller ._polling_method ._deserialization_callback , # type: ignore # pylint: disable=protected-access
282- poller ._polling_method , # pylint: disable=protected-access
283- )
272+ # Wrap in custom poller with .operation_id property (without re-initializing)
273+ return AnalyzeAsyncLROPoller .from_poller (poller ) # pyright: ignore[reportReturnType]
284274
285275
286276def patch_sdk ():
Original file line number Diff line number Diff line change @@ -59,6 +59,24 @@ def operation_id(self) -> str:
5959 except (KeyError , ValueError ) as e :
6060 raise ValueError (f"Could not extract operation ID: { str (e )} " ) from e
6161
62+ @classmethod
63+ def from_poller (cls , poller : AsyncLROPoller [PollingReturnType_co ]) -> "AnalyzeAsyncLROPoller[PollingReturnType_co]" :
64+ """Wrap an existing AsyncLROPoller without re-initializing the polling method.
65+
66+ This avoids duplicate HTTP requests that would occur if we created a new
67+ AsyncLROPoller instance (which calls polling_method.initialize() again).
68+
69+ :param poller: The existing AsyncLROPoller to wrap
70+ :type poller: ~azure.core.polling.AsyncLROPoller
71+ :return: An AnalyzeAsyncLROPoller wrapping the same polling state
72+ :rtype: AnalyzeAsyncLROPoller
73+ """
74+ # Create instance without calling __init__ to avoid re-initialization
75+ instance : AnalyzeAsyncLROPoller [PollingReturnType_co ] = object .__new__ (cls )
76+ # Copy all attributes from the original poller
77+ instance .__dict__ .update (poller .__dict__ )
78+ return instance
79+
6280 @classmethod
6381 async def from_continuation_token ( # type: ignore[override] # pylint: disable=invalid-overridden-method
6482 cls ,
Original file line number Diff line number Diff line change @@ -90,6 +90,24 @@ def operation_id(self) -> str:
9090 except (KeyError , ValueError ) as e :
9191 raise ValueError (f"Could not extract operation ID: { str (e )} " ) from e
9292
93+ @classmethod
94+ def from_poller (cls , poller : LROPoller [PollingReturnType_co ]) -> "AnalyzeLROPoller[PollingReturnType_co]" :
95+ """Wrap an existing LROPoller without re-initializing the polling method.
96+
97+ This avoids duplicate HTTP requests that would occur if we created a new
98+ LROPoller instance (which calls polling_method.initialize() again).
99+
100+ :param poller: The existing LROPoller to wrap
101+ :type poller: ~azure.core.polling.LROPoller
102+ :return: An AnalyzeLROPoller wrapping the same polling state
103+ :rtype: AnalyzeLROPoller
104+ """
105+ # Create instance without calling __init__ to avoid re-initialization
106+ instance : AnalyzeLROPoller [PollingReturnType_co ] = object .__new__ (cls )
107+ # Copy all attributes from the original poller
108+ instance .__dict__ .update (poller .__dict__ )
109+ return instance
110+
93111 @classmethod
94112 def from_continuation_token (
95113 cls , polling_method : PollingMethod [PollingReturnType_co ], continuation_token : str , ** kwargs : Any
You can’t perform that action at this time.
0 commit comments