@@ -574,27 +574,6 @@ def __init__(self, lock_class: LockTypeClass) -> None:
574574 # Try this way too
575575 Foobar (self .lock_class )
576576
577- def test_subclassing_wrapped_lock (self ) -> None :
578- """Test that subclassing of a wrapped lock type when profiling is active."""
579- from ddtrace .profiling .collector ._lock import _LockAllocatorWrapper
580-
581- with self .collector_class ():
582- assert isinstance (self .lock_class , _LockAllocatorWrapper )
583-
584- # This should NOT raise TypeError
585- class CustomLock (self .lock_class ): # type: ignore[misc]
586- def __init__ (self ) -> None :
587- super ().__init__ ()
588- self .custom_attr : str = "test"
589-
590- # Verify subclassing and functionality
591- custom_lock : CustomLock = CustomLock ()
592- assert hasattr (custom_lock , "custom_attr" )
593- assert custom_lock .custom_attr == "test"
594-
595- assert custom_lock .acquire ()
596- custom_lock .release ()
597-
598577 def test_lock_events (self ) -> None :
599578 # The first argument is the recorder.Recorder which is used for the
600579 # v1 exporter. We don't need it for the v2 exporter.
@@ -1410,6 +1389,32 @@ class BaseSemaphoreTest(BaseThreadingLockCollectorTest):
14101389 particularly those related to internal lock detection and Condition-based implementation.
14111390 """
14121391
1392+ def test_subclassing_wrapped_lock (self ) -> None :
1393+ """Test that subclassing of a wrapped lock type works when profiling is active.
1394+
1395+ This test is only valid for Semaphore-like types (pure Python classes).
1396+ threading.Lock and threading.RLock are C types that don't support subclassing
1397+ through __mro_entries__.
1398+ """
1399+ from ddtrace .profiling .collector ._lock import _LockAllocatorWrapper
1400+
1401+ with self .collector_class ():
1402+ assert isinstance (self .lock_class , _LockAllocatorWrapper )
1403+
1404+ # This should NOT raise TypeError
1405+ class CustomLock (self .lock_class ): # type: ignore[misc]
1406+ def __init__ (self ) -> None :
1407+ super ().__init__ ()
1408+ self .custom_attr : str = "test"
1409+
1410+ # Verify subclassing and functionality
1411+ custom_lock : CustomLock = CustomLock ()
1412+ assert hasattr (custom_lock , "custom_attr" )
1413+ assert custom_lock .custom_attr == "test"
1414+
1415+ assert custom_lock .acquire ()
1416+ custom_lock .release ()
1417+
14131418 def _verify_no_double_counting (self , marker_name : str , lock_var_name : str ) -> None :
14141419 """Helper method to verify no double-counting in profile output.
14151420
0 commit comments