Skip to content

Commit de742d1

Browse files
xiangyan99sofiar-msft
authored andcommitted
fix typing (Azure#34227)
1 parent 3e1e67e commit de742d1

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

sdk/identity/azure-identity-broker/azure/identity/broker/_utils.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ def wrapper(*args, **kwargs):
3535

3636

3737
def resolve_tenant(
38-
default_tenant: str, tenant_id: Optional[str] = None, *, additionally_allowed_tenants: List[str] = [], **_
38+
default_tenant: str,
39+
tenant_id: Optional[str] = None,
40+
*,
41+
additionally_allowed_tenants: Optional[List[str]] = None,
42+
**_
3943
) -> str:
4044
"""Returns the correct tenant for a token request given a credential's configuration.
4145
@@ -59,6 +63,8 @@ def resolve_tenant(
5963
return default_tenant
6064
if not default_tenant:
6165
return tenant_id
66+
if additionally_allowed_tenants is None:
67+
additionally_allowed_tenants = []
6268
if "*" in additionally_allowed_tenants or tenant_id in additionally_allowed_tenants:
6369
_LOGGER.info(
6470
"A token was requested for a different tenant than was configured on the credential, "

sdk/identity/azure-identity/azure/identity/_internal/utils.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ def validate_tenant_id(tenant_id: str) -> None:
7373

7474

7575
def resolve_tenant(
76-
default_tenant: str, tenant_id: Optional[str] = None, *, additionally_allowed_tenants: List[str] = [], **_
76+
default_tenant: str,
77+
tenant_id: Optional[str] = None,
78+
*,
79+
additionally_allowed_tenants: Optional[List[str]] = None,
80+
**_
7781
) -> str:
7882
"""Returns the correct tenant for a token request given a credential's configuration.
7983
@@ -97,6 +101,8 @@ def resolve_tenant(
97101
return default_tenant
98102
if not default_tenant:
99103
return tenant_id
104+
if additionally_allowed_tenants is None:
105+
additionally_allowed_tenants = []
100106
if "*" in additionally_allowed_tenants or tenant_id in additionally_allowed_tenants:
101107
_LOGGER.info(
102108
"A token was requested for a different tenant than was configured on the credential, "

sdk/identity/azure-identity/azure/identity/aio/_credentials/azd_cli.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ async def _run_command(command: str, timeout: int) -> str:
171171
stdout_b, stderr_b = await asyncio.wait_for(proc.communicate(), timeout)
172172
output = stdout_b.decode()
173173
stderr = stderr_b.decode()
174+
except asyncio.TimeoutError as ex:
175+
proc.kill()
176+
raise CredentialUnavailableError(message="Timed out waiting for Azure Developer CLI") from ex
174177
except OSError as ex:
175178
# failed to execute 'cmd' or '/bin/sh'
176179
error = CredentialUnavailableError(message="Failed to execute '{}'".format(args[0]))
177180
raise error from ex
178-
except asyncio.TimeoutError as ex:
179-
proc.kill()
180-
raise CredentialUnavailableError(message="Timed out waiting for Azure Developer CLI") from ex
181181

182182
if proc.returncode == 0:
183183
return output

sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_cli.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ async def _run_command(command: str, timeout: int) -> str:
149149
stdout_b, stderr_b = await asyncio.wait_for(proc.communicate(), timeout)
150150
output = stdout_b.decode()
151151
stderr = stderr_b.decode()
152+
except asyncio.TimeoutError as ex:
153+
proc.kill()
154+
raise CredentialUnavailableError(message="Timed out waiting for Azure CLI") from ex
152155
except OSError as ex:
153156
# failed to execute 'cmd' or '/bin/sh'
154157
error = CredentialUnavailableError(message="Failed to execute '{}'".format(args[0]))
155158
raise error from ex
156-
except asyncio.TimeoutError as ex:
157-
proc.kill()
158-
raise CredentialUnavailableError(message="Timed out waiting for Azure CLI") from ex
159159

160160
if proc.returncode == 0:
161161
return output

sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_powershell.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ async def run_command_line(command_line: List[str], timeout: int) -> str:
114114
proc = await start_process(command_line)
115115
stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout)
116116

117+
except asyncio.TimeoutError as ex:
118+
proc.kill()
119+
raise CredentialUnavailableError(
120+
message="Timed out waiting for Azure PowerShell.\n"
121+
"To mitigate this issue, please refer to the troubleshooting guidelines here at "
122+
"https://aka.ms/azsdk/python/identity/powershellcredential/troubleshoot."
123+
) from ex
117124
except OSError as ex:
118125
# failed to execute "cmd" or "/bin/sh"; Azure PowerShell may or may not be installed
119126
error = CredentialUnavailableError(
@@ -122,13 +129,6 @@ async def run_command_line(command_line: List[str], timeout: int) -> str:
122129
"https://aka.ms/azsdk/python/identity/powershellcredential/troubleshoot.".format(command_line[0])
123130
)
124131
raise error from ex
125-
except asyncio.TimeoutError as ex:
126-
proc.kill()
127-
raise CredentialUnavailableError(
128-
message="Timed out waiting for Azure PowerShell.\n"
129-
"To mitigate this issue, please refer to the troubleshooting guidelines here at "
130-
"https://aka.ms/azsdk/python/identity/powershellcredential/troubleshoot."
131-
) from ex
132132

133133
decoded_stdout = stdout.decode()
134134

0 commit comments

Comments
 (0)