@@ -377,11 +377,12 @@ async def __anext__(self) -> T:
377377
378378
379379class HTTPClient :
380- __slots__ = ("_client_id" , "_session" , "_should_close" , "user_agent" )
380+ __slots__ = ("_client_id" , "_session" , "_session_set" , " _should_close" , "user_agent" )
381381
382382 def __init__ (self , session : aiohttp .ClientSession = MISSING , * , client_id : str ) -> None :
383383 self ._session : aiohttp .ClientSession = session
384384 self ._should_close : bool = session is MISSING
385+ self ._session_set : bool = False
385386
386387 self ._client_id : str = client_id
387388
@@ -395,6 +396,11 @@ def headers(self) -> dict[str, str]:
395396 return {"User-Agent" : self .user_agent , "Client-ID" : self ._client_id }
396397
397398 async def _init_session (self ) -> None :
399+ if self ._session_set :
400+ return
401+
402+ self ._session_set = True
403+
398404 if self ._session is not MISSING :
399405 self ._session .headers .update (self .headers )
400406 return
@@ -408,6 +414,7 @@ def clear(self) -> None:
408414 "Clearing %s session. A new session will be created on the next request." , self .__class__ .__qualname__
409415 )
410416 self ._session = MISSING
417+ self ._session_set = False
411418
412419 async def close (self ) -> None :
413420 if not self ._should_close :
0 commit comments