@@ -51,41 +51,30 @@ def teardown_method(self):
5151 except Exception as e :
5252 print ("Error while deleting file: " , e )
5353
54- def test_subclassing_wrapped_lock (self ):
55- """Test that subclassing asyncio.Lock works when profiling is active.
54+ def test_subclassing_wrapped_lock (self ) -> None :
55+ """Test that subclassing of a wrapped lock type when profiling is active."""
56+ from typing import Optional
5657
57- Regression test for a bug reported by neo4j users where their library defines:
58- class AsyncRLock(asyncio.Lock): ...
59-
60- With profiling enabled, this would fail with:
61- TypeError: _LockAllocatorWrapper.__init__() takes 2 positional arguments but 4 were given
62-
63- The fix implements __mro_entries__ on _LockAllocatorWrapper (PEP 560).
64- """
6558 from ddtrace .profiling .collector ._lock import _LockAllocatorWrapper
6659
6760 with collector_asyncio .AsyncioLockCollector (capture_pct = 100 ):
68- # Verify the wrapper is in place
6961 assert isinstance (asyncio .Lock , _LockAllocatorWrapper )
7062
7163 # This should NOT raise TypeError
72- class AsyncRLock (asyncio .Lock ):
73- """A custom lock that extends asyncio.Lock (like neo4j does)."""
74-
64+ class CustomLock (asyncio .Lock ): # type: ignore[misc]
7565 def __init__ (self ) -> None :
7666 super ().__init__ ()
77- self ._owner = None
78- self ._count = 0
67+ self ._owner : Optional [ int ] = None
68+ self ._count : int = 0
7969
80- # Verify the subclass can be instantiated
81- custom_lock = AsyncRLock ()
70+ # Verify subclassing and functionality
71+ custom_lock : CustomLock = CustomLock ()
8272 assert hasattr (custom_lock , "_owner" )
8373 assert hasattr (custom_lock , "_count" )
8474 assert custom_lock ._owner is None
8575 assert custom_lock ._count == 0
8676
87- # Verify async lock functionality still works
88- async def test_async_lock ():
77+ async def test_async_lock () -> None :
8978 await custom_lock .acquire ()
9079 assert custom_lock .locked ()
9180 custom_lock .release ()
0 commit comments