Skip to content

Commit 77ad70e

Browse files
MichaelZp0Michael Zappe
andauthored
Fix linting issues in the Azure Remote Rendering SDK (#35517)
* Fix a lot of linting issues * Fix mypy issues * Remove type from kwargs * Remove any added kwargs: Any instance --------- Co-authored-by: Michael Zappe <[email protected]>
1 parent 1c726a9 commit 77ad70e

11 files changed

+151
-249
lines changed

sdk/remoterendering/azure-mixedreality-remoterendering/azure/mixedreality/remoterendering/_polling.py

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,87 +6,73 @@
66
import base64
77
import time
88
from functools import partial
9-
from typing import TYPE_CHECKING
9+
from typing import Any, Callable, Union
1010

1111
from azure.core.polling import PollingMethod
1212
from azure.core.exceptions import HttpResponseError, ODataV4Format
1313

1414
from ._generated.models import (AssetConversion, AssetConversionStatus,
1515
RenderingSession, RenderingSessionStatus)
1616

17-
# pylint: disable=unsubscriptable-object
18-
if TYPE_CHECKING:
19-
# pylint: disable=unused-import,ungrouped-imports
20-
from typing import Any, Callable, Union
21-
22-
from azure.core.credentials import TokenCredential
23-
24-
from ._generated import RemoteRenderingRestClient
17+
from ._generated import RemoteRenderingRestClient
2518

2619

2720
class RemoteRenderingPolling(PollingMethod):
2821
""" Abstract base class for polling.
2922
"""
3023

31-
def __init__(self, account_id, is_terminated, polling_interval=5):
32-
# type: (str, Callable, int) -> None
24+
def __init__(self, account_id: str, is_terminated: Callable, polling_interval: int=5) -> None:
3325
self._account_id = account_id
34-
self._response = None # type: Union[AssetConversion, RenderingSession, None]
35-
self._client = None # type: Union[RemoteRenderingRestClient, None]
26+
self._response: Union[AssetConversion, RenderingSession, None] = None
27+
self._client: Union[RemoteRenderingRestClient, None] = None
3628
self._query_status = None
3729
self._is_terminated = is_terminated
3830
self._polling_interval = polling_interval
3931

40-
def _update_status(self):
41-
# type: () -> None
32+
def _update_status(self) -> None:
4233
if self._query_status is None:
4334
raise RuntimeError("this poller has not been initialized")
4435
self._response = self._query_status() # pylint: disable=E1102
45-
if self._response.error is not None:
36+
if self._response.error is not None: # type: ignore
4637
error = HttpResponseError("Polling returned a status indicating an error state.", model=self._response)
47-
error.error = ODataV4Format(self._response.error.serialize())
38+
error.error = ODataV4Format(self._response.error.serialize()) # type: ignore
4839
raise error
4940

50-
def initialize(self, client, initial_response, deserialization_callback):
51-
# type: (Any, Any, Callable) -> None
41+
def initialize(self, client: Any, initial_response: Any, deserialization_callback: Callable) -> None:
5242
self._client = client
5343
self._response = initial_response
5444

55-
def run(self):
56-
# type: () -> None
45+
def run(self) -> None:
5746
while not self.finished():
5847
self._update_status()
5948
if not self.finished():
6049
time.sleep(self._polling_interval)
6150

62-
def status(self):
63-
# type: () -> str
51+
def status(self) -> str:
6452
raise NotImplementedError("This method needs to be implemented")
6553

66-
def finished(self):
67-
# type: () -> bool
54+
def finished(self) -> bool:
6855
if self._response is None:
6956
return False
7057
if self._response.status is None:
7158
return False
7259
return self._is_terminated(self._response.status)
7360

74-
def resource(self):
75-
# type: () -> Union[AssetConversion, RenderingSession, None]
61+
def resource(self) -> Union[AssetConversion, RenderingSession, None]:
7662
if not self.finished():
7763
return None
7864
return self._response
7965

80-
def get_continuation_token(self):
81-
# type() -> str
82-
66+
def get_continuation_token(self) -> str:
8367
# returns a Base64 encoded string of "<version>:<account_id>:<session_id/conversion_id>"
84-
return base64.b64encode(("1:"+self._account_id+":"+self._response.id).encode('ascii')).decode('ascii')
68+
token_str = "1:"+self._account_id+":"+self._response.id # type: ignore
69+
encoded = token_str.encode('ascii')
70+
base64_endcoded = base64.b64encode(encoded)
71+
return base64_endcoded.decode('ascii')
8572

8673

8774
class ConversionPolling(RemoteRenderingPolling):
88-
def __init__(self, account_id, polling_interval=5):
89-
# type: (str, int) -> None
75+
def __init__(self, account_id: str, polling_interval: int=5) -> None:
9076
def is_terminated(status):
9177
return status in [
9278
AssetConversionStatus.FAILED,
@@ -97,26 +83,23 @@ def is_terminated(status):
9783
is_terminated=is_terminated,
9884
polling_interval=polling_interval)
9985

100-
def initialize(self, client, initial_response, deserialization_callback):
101-
# type: (Any, Any, Any, Callable) -> None
86+
def initialize(self, client: Any, initial_response: Any, deserialization_callback: Callable) -> None:
10287
super(ConversionPolling, self).initialize(client=client,
10388
initial_response=initial_response,
10489
deserialization_callback=deserialization_callback)
10590
self._query_status = partial(
106-
self._client.remote_rendering.get_conversion,
91+
self._client.remote_rendering.get_conversion, # type: ignore
10792
account_id=self._account_id,
108-
conversion_id=initial_response.id)
93+
conversion_id=initial_response.id) # type: ignore
10994

110-
def status(self):
111-
# type: () -> str
95+
def status(self) -> str:
11296
if self._response is None:
11397
return AssetConversionStatus.NOT_STARTED
11498
return self._response.status
11599

116100
@classmethod
117101
def from_continuation_token(cls, continuation_token, client, **kwargs): # pylint: disable=W0221
118102
# type(str, RemoteRenderingRestClient, Any) -> Tuple
119-
120103
version, account_id, conversion_id = base64.b64decode(
121104
continuation_token.encode('ascii')).decode('ascii').split(":")
122105

@@ -132,8 +115,7 @@ def from_continuation_token(cls, continuation_token, client, **kwargs): # pylin
132115

133116

134117
class SessionPolling(RemoteRenderingPolling):
135-
def __init__(self, account_id, polling_interval=2):
136-
# type: (str, int) -> None
118+
def __init__(self, account_id: str, polling_interval: int=2) -> None:
137119
def is_terminated(status):
138120
return status in [
139121
RenderingSessionStatus.EXPIRED,
@@ -145,22 +127,21 @@ def is_terminated(status):
145127
is_terminated=is_terminated,
146128
polling_interval=polling_interval)
147129

148-
def initialize(self, client, initial_response, deserialization_callback):
149-
# type: (Any, Any, Any, Callable) -> None
130+
def initialize(self, client: Any, initial_response: Any, deserialization_callback: Callable) -> None:
150131
super(SessionPolling, self).initialize(client, initial_response, deserialization_callback)
151132
self._query_status = partial(
152-
self._client.remote_rendering.get_session, account_id=self._account_id, session_id=initial_response.id)
133+
self._client.remote_rendering.get_session, # type: ignore
134+
account_id=self._account_id,
135+
session_id=initial_response.id) # type: ignore
153136

154-
def status(self):
155-
# type: () -> str
137+
def status(self) -> str:
156138
if self._response is None:
157139
return RenderingSessionStatus.STARTING
158140
return self._response.status
159141

160142
@classmethod
161143
def from_continuation_token(cls, continuation_token, client, **kwargs): # pylint: disable=W0221
162144
# type(str, RemoteRenderingRestClient, Any) -> Tuple
163-
164145
version, account_id, session_id = base64.b64decode(
165146
continuation_token.encode('ascii')).decode('ascii').split(":")
166147

sdk/remoterendering/azure-mixedreality-remoterendering/azure/mixedreality/remoterendering/_remote_rendering_client.py

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
# --------------------------------------------------------------------------
77

88

9-
from typing import TYPE_CHECKING, Any, Callable, Union
9+
from typing import Any, Callable, Union
1010

1111
from azure.core.credentials import AccessToken, AzureKeyCredential
1212
from azure.core.paging import ItemPaged
1313
from azure.core.pipeline.policies import BearerTokenCredentialPolicy
1414
from azure.core.polling import LROPoller
1515
from azure.core.tracing.decorator import distributed_trace
16+
from azure.core.credentials import TokenCredential
1617

1718
from ._api_version import validate_api_version, DEFAULT_VERSION
1819
from ._generated import RemoteRenderingRestClient
@@ -32,12 +33,6 @@
3233
from ._shared.static_access_token_credential import StaticAccessTokenCredential
3334
from ._version import SDK_MONIKER
3435

35-
if TYPE_CHECKING:
36-
from azure.core.credentials import TokenCredential
37-
38-
# pylint: disable=unsubscriptable-object
39-
40-
4136
class RemoteRenderingClient:
4237
"""A client for the Azure Remote Rendering Service.
4338
@@ -126,8 +121,11 @@ def __init__(self,
126121
**kwargs)
127122

128123
@distributed_trace
129-
def begin_asset_conversion(self, conversion_id, input_settings, output_settings, **kwargs):
130-
# type: (str, AssetConversionInputSettings, AssetConversionOutputSettings, Any) -> LROPoller[AssetConversion]
124+
def begin_asset_conversion(self,
125+
conversion_id: str,
126+
input_settings: AssetConversionInputSettings,
127+
output_settings: AssetConversionOutputSettings,
128+
**kwargs) -> LROPoller[AssetConversion]:
131129
"""
132130
Start a new asset conversion with the given options.
133131
:param str conversion_id:
@@ -161,8 +159,7 @@ def begin_asset_conversion(self, conversion_id, input_settings, output_settings,
161159
polling_method=polling_method)
162160

163161
@distributed_trace
164-
def get_asset_conversion(self, conversion_id, **kwargs):
165-
# type: (str, Any) -> AssetConversion
162+
def get_asset_conversion(self, conversion_id: str, **kwargs) -> AssetConversion:
166163
"""
167164
Retrieve the state of a previously created conversion.
168165
:param str conversion_id:
@@ -175,23 +172,19 @@ def get_asset_conversion(self, conversion_id, **kwargs):
175172
account_id=self._account_id, conversion_id=conversion_id, **kwargs)
176173

177174
@distributed_trace
178-
def get_asset_conversion_poller(self, **kwargs):
179-
# type: (Any) -> LROPoller[AssetConversion]
175+
def get_asset_conversion_poller(self, **kwargs) -> LROPoller[AssetConversion]: # pylint:disable=docstring-keyword-should-match-keyword-only
180176
"""
181177
Returns a poller for an existing conversion by conversion id or a continuation token retrieved from a previous
182178
poller.
183-
:keyword conversion_id: The conversion id of a previously created conversion.
184-
:paramtype conversion_id: str
185-
:keyword continuation_token:
186-
A continuation token retrieved from a poller of a conversion.
187-
:paramtype continuation_token: str
179+
:keyword str conversion_id: The conversion_id of a previously created conversion.
180+
:keyword str continuation_token: A continuation token retrieved from a poller of a conversion.
188181
:return: A poller for the created asset conversion
189182
:rtype: ~azure.core.polling.LROPoller[AssetConversion]
190183
:raises ~azure.core.exceptions.HttpResponseError:
191184
"""
192185

193-
conversion_id = kwargs.pop("conversion_id", None) # type: Union[str,None]
194-
continuation_token = kwargs.pop("continuation_token", None) # type: Union[str,None]
186+
conversion_id: Union[str,None] = kwargs.pop("conversion_id", None)
187+
continuation_token: Union[str,None] = kwargs.pop("continuation_token", None)
195188

196189
if conversion_id is None and continuation_token is None:
197190
raise ValueError(
@@ -222,18 +215,20 @@ def get_asset_conversion_poller(self, **kwargs):
222215
polling_method=polling_method)
223216

224217
@distributed_trace
225-
def list_asset_conversions(self, **kwargs):
226-
# type: (...) -> ItemPaged[AssetConversion]
218+
def list_asset_conversions(self, **kwargs) -> ItemPaged[AssetConversion]:
227219
""" Returns list of conversions for the remote rendering account.
228220
:rtype: ItemPaged[AssetConversion]
229221
:raises ~azure.core.exceptions.HttpResponseError:
230222
:return: List of conversion for the remote rendering account.
231223
"""
232-
return self._client.remote_rendering.list_conversions(account_id=self._account_id, **kwargs) # type: ignore
224+
return self._client.remote_rendering.list_conversions(account_id=self._account_id, **kwargs) # type: ignore
233225

234226
@distributed_trace
235-
def begin_rendering_session(self, session_id, size, lease_time_minutes, **kwargs):
236-
# type: (str, Union[str, RenderingSessionSize], int, Any) -> LROPoller[RenderingSession]
227+
def begin_rendering_session(self,
228+
session_id: str,
229+
size: Union[str, RenderingSessionSize],
230+
lease_time_minutes: int,
231+
**kwargs) -> LROPoller[RenderingSession]:
237232
"""
238233
:param str session_id: An ID uniquely identifying the rendering session for the given account. The ID is case
239234
sensitive, can contain any combination of alphanumeric characters including hyphens and underscores, and
@@ -263,8 +258,7 @@ def begin_rendering_session(self, session_id, size, lease_time_minutes, **kwargs
263258
polling_method=polling_method)
264259

265260
@distributed_trace
266-
def get_rendering_session(self, session_id, **kwargs):
267-
# type: (str, Any) -> RenderingSession
261+
def get_rendering_session(self, session_id: str, **kwargs) -> RenderingSession:
268262
'''
269263
Returns the properties of a previously generated rendering session.
270264
:param str session_id: The identifier of the rendering session.
@@ -278,23 +272,19 @@ def get_rendering_session(self, session_id, **kwargs):
278272
**kwargs)
279273

280274
@distributed_trace
281-
def get_rendering_session_poller(self, **kwargs):
282-
# type: (Any) -> LROPoller[RenderingSession]
275+
def get_rendering_session_poller(self, **kwargs) -> LROPoller[RenderingSession]: # pylint:disable=docstring-keyword-should-match-keyword-only
283276
"""
284277
Returns a poller for an existing rendering session by session id or a continuation token retrieved from a
285278
previous poller.
286-
:keyword session_id: The conversion id of a previously created conversion.
287-
:paramtype session_id: str
288-
:keyword continuation_token:
289-
A continuation token retrieved from a poller of a session.
290-
:paramtype continuation_token: str
279+
:keyword str session_id: The conversion id of a previously created conversion.
280+
:keyword str continuation_token: A continuation token retrieved from a poller of a session.
291281
:return: A session poller for the given session
292282
:rtype: LROPoller[RenderingSession]
293283
:raises ~azure.core.exceptions.HttpResponseError:
294284
"""
295285

296-
session_id = kwargs.pop("session_id", None) # type: Union[str,None]
297-
continuation_token = kwargs.pop("continuation_token", None) # type: Union[str,None]
286+
session_id: Union[str,None] = kwargs.pop("session_id", None)
287+
continuation_token: Union[str,None] = kwargs.pop("continuation_token", None)
298288

299289
if session_id is None and continuation_token is None:
300290
raise ValueError(
@@ -325,8 +315,7 @@ def get_rendering_session_poller(self, **kwargs):
325315
polling_method=polling_method)
326316

327317
@distributed_trace
328-
def stop_rendering_session(self, session_id, **kwargs):
329-
# type: (str, Any) -> None
318+
def stop_rendering_session(self, session_id: str, **kwargs) -> None:
330319
"""
331320
:param str session_id: The identifier of the session to be stopped.
332321
:return: None
@@ -337,20 +326,18 @@ def stop_rendering_session(self, session_id, **kwargs):
337326
account_id=self._account_id, session_id=session_id, **kwargs)
338327

339328
@distributed_trace
340-
def update_rendering_session(self, session_id, **kwargs):
341-
# type: (str, Any) -> RenderingSession
329+
def update_rendering_session(self, session_id: str, **kwargs) -> RenderingSession: # pylint:disable=docstring-keyword-should-match-keyword-only
342330
"""
343331
Updates an already existing rendering session.
344332
:param str session_id: The identifier of the session to be updated.
345-
:keyword lease_time_minutes: The new lease time of the rendering session. Has to be strictly larger than
333+
:keyword int lease_time_minutes: The new lease time of the rendering session. Has to be strictly larger than
346334
the previous lease time.
347-
:paramtype lease_time_minutes: int
348335
:return: The properties of the updated session
349336
:rtype: ~azure.mixedreality.remoterendering.models.RenderingSession
350337
:raises ~azure.core.exceptions.HttpResponseError:
351338
"""
352339

353-
lease_time_minutes = kwargs.pop("lease_time_minutes", None) # type: Union[int,None]
340+
lease_time_minutes: Union[int,None] = kwargs.pop("lease_time_minutes", None)
354341
if lease_time_minutes is not None:
355342
return self._client.remote_rendering.update_session(account_id=self._account_id,
356343
session_id=session_id,
@@ -364,8 +351,7 @@ def update_rendering_session(self, session_id, **kwargs):
364351
**kwargs)
365352

366353
@distributed_trace
367-
def list_rendering_sessions(self, **kwargs):
368-
# type: (...) -> ItemPaged[RenderingSession]
354+
def list_rendering_sessions(self, **kwargs) -> ItemPaged[RenderingSession]:
369355
"""
370356
Returns list of rendering sessions in the 'Ready' or 'Starting' state.
371357
Does not return stopped or failed rendering sessions.
@@ -375,15 +361,12 @@ def list_rendering_sessions(self, **kwargs):
375361
"""
376362
return self._client.remote_rendering.list_sessions(account_id=self._account_id, **kwargs) # type: ignore
377363

378-
def close(self):
379-
# type: () -> None
364+
def close(self) -> None:
380365
self._client.close()
381366

382-
def __enter__(self):
383-
# type: () -> RemoteRenderingClient
367+
def __enter__(self) -> "RemoteRenderingClient":
384368
self._client.__enter__() # pylint:disable=no-member
385369
return self
386370

387-
def __exit__(self, *args):
388-
# type: (*Any) -> None
371+
def __exit__(self, *args: Any) -> None:
389372
self._client.__exit__(*args) # pylint:disable=no-member

0 commit comments

Comments
 (0)