@@ -80,6 +80,8 @@ class SemaphoreStatistics:
8080
8181
8282class Event :
83+ __slots__ = ("__weakref__" ,)
84+
8385 def __new__ (cls ) -> Event :
8486 try :
8587 return get_async_backend ().create_event ()
@@ -110,12 +112,15 @@ def statistics(self) -> EventStatistics:
110112
111113
112114class EventAdapter (Event ):
113- _internal_event : Event | None = None
114- _is_set : bool = False
115+ __slots__ = "_internal_event" , "_is_set"
115116
116117 def __new__ (cls ) -> EventAdapter :
117118 return object .__new__ (cls )
118119
120+ def __init__ (self ) -> None :
121+ self ._internal_event : Event | None = None
122+ self ._is_set = False
123+
119124 @property
120125 def _event (self ) -> Event :
121126 if self ._internal_event is None :
@@ -148,6 +153,8 @@ def statistics(self) -> EventStatistics:
148153
149154
150155class Lock :
156+ __slots__ = ("__weakref__" ,)
157+
151158 def __new__ (cls , * , fast_acquire : bool = False ) -> Lock :
152159 try :
153160 return get_async_backend ().create_lock (fast_acquire = fast_acquire )
@@ -196,12 +203,13 @@ def statistics(self) -> LockStatistics:
196203
197204
198205class LockAdapter (Lock ):
199- _internal_lock : Lock | None = None
206+ __slots__ = "_internal_lock" , "_fast_acquire"
200207
201208 def __new__ (cls , * , fast_acquire : bool = False ) -> LockAdapter :
202209 return object .__new__ (cls )
203210
204211 def __init__ (self , * , fast_acquire : bool = False ):
212+ self ._internal_lock : Lock | None = None
205213 self ._fast_acquire = fast_acquire
206214
207215 @property
@@ -260,9 +268,10 @@ def statistics(self) -> LockStatistics:
260268
261269
262270class Condition :
263- _owner_task : TaskInfo | None = None
271+ __slots__ = "__weakref__" , "_owner_task" , "_lock" , "_waiters"
264272
265273 def __init__ (self , lock : Lock | None = None ):
274+ self ._owner_task : TaskInfo | None = None
266275 self ._lock = lock or Lock ()
267276 self ._waiters : deque [Event ] = deque ()
268277
@@ -371,6 +380,8 @@ def statistics(self) -> ConditionStatistics:
371380
372381
373382class Semaphore :
383+ __slots__ = "__weakref__" , "_fast_acquire"
384+
374385 def __new__ (
375386 cls ,
376387 initial_value : int ,
@@ -455,7 +466,7 @@ def statistics(self) -> SemaphoreStatistics:
455466
456467
457468class SemaphoreAdapter (Semaphore ):
458- _internal_semaphore : Semaphore | None = None
469+ __slots__ = "_internal_semaphore" , "_initial_value" , "_max_value"
459470
460471 def __new__ (
461472 cls ,
@@ -474,6 +485,7 @@ def __init__(
474485 fast_acquire : bool = False ,
475486 ) -> None :
476487 super ().__init__ (initial_value , max_value = max_value , fast_acquire = fast_acquire )
488+ self ._internal_semaphore : Semaphore | None = None
477489 self ._initial_value = initial_value
478490 self ._max_value = max_value
479491
@@ -514,6 +526,8 @@ def statistics(self) -> SemaphoreStatistics:
514526
515527
516528class CapacityLimiter :
529+ __slots__ = ("__weakref__" ,)
530+
517531 def __new__ (cls , total_tokens : float ) -> CapacityLimiter :
518532 try :
519533 return get_async_backend ().create_capacity_limiter (total_tokens )
@@ -630,12 +644,13 @@ def statistics(self) -> CapacityLimiterStatistics:
630644
631645
632646class CapacityLimiterAdapter (CapacityLimiter ):
633- _internal_limiter : CapacityLimiter | None = None
647+ __slots__ = "_internal_limiter" , "_total_tokens"
634648
635649 def __new__ (cls , total_tokens : float ) -> CapacityLimiterAdapter :
636650 return object .__new__ (cls )
637651
638652 def __init__ (self , total_tokens : float ) -> None :
653+ self ._internal_limiter : CapacityLimiter | None = None
639654 self .total_tokens = total_tokens
640655
641656 @property
@@ -736,7 +751,7 @@ class ResourceGuard:
736751 .. versionadded:: 4.1
737752 """
738753
739- __slots__ = "action" , "_guarded"
754+ __slots__ = "__weakref__" , " action" , "_guarded"
740755
741756 def __init__ (self , action : str = "using" ):
742757 self .action : str = action
0 commit comments