Skip to content

Commit 4912f5a

Browse files
author
Martin Lambertsen
authored
fix: avoid using default mutable arguments
Using mutable default arguments is a common Python problem, see e.g. https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments In this specific case the default argument even tries to setup some infrastructure settings at import time, which can potentially fail. Note that this commit is changing the behavior for user passing in `None` to the changed method, as it will now create an `AsyncClient` with the options specified within the module. In the previous behavior it would have raised an exception deeper down the call stack (see http://github.com/microsoft/kiota-http-python/pull/383/files).
1 parent a9de70b commit 4912f5a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

msgraph/graph_request_adapter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, Optional
1+
from typing import Optional
22
import httpx
33
from kiota_abstractions.authentication import AuthenticationProvider
44
from kiota_http.middleware.options import UrlReplaceHandlerOption
@@ -20,5 +20,7 @@
2020

2121
class GraphRequestAdapter(BaseGraphRequestAdapter):
2222
def __init__(self, auth_provider: AuthenticationProvider,
23-
client: Optional[httpx.AsyncClient] = GraphClientFactory.create_with_default_middleware(options=options)) -> None:
23+
client: Optional[httpx.AsyncClient] = None) -> None:
24+
if client is None:
25+
client = GraphClientFactory.create_with_default_middleware(options=options)
2426
super().__init__(auth_provider, http_client=client)

0 commit comments

Comments
 (0)