99DeviceManager.
1010"""
1111
12- from __future__ import annotations
13-
1412import time
1513from collections import Counter
1614from collections .abc import Generator , Mapping
1715from contextlib import contextmanager
18- from typing import Any , TypeVar , cast
16+ from typing import Any , Self , TypeVar , cast
1917
2018
2119class Diagnostics :
@@ -28,7 +26,7 @@ class Diagnostics:
2826 def __init__ (self ) -> None :
2927 """Initialize Diagnostics."""
3028 self ._counter : Counter = Counter ()
31- self ._subkeys : dict [str , Diagnostics ] = {}
29+ self ._subkeys : dict [str , Self ] = {}
3230
3331 def increment (self , key : str , count : int = 1 ) -> None :
3432 """Increment a counter for the specified key/event."""
@@ -49,7 +47,7 @@ def as_dict(self) -> Mapping[str, Any]:
4947 data [k ] = v
5048 return data
5149
52- def subkey (self , key : str ) -> Diagnostics :
50+ def subkey (self , key : str ) -> Self :
5351 """Return sub-Diagnostics object with the specified subkey.
5452
5553 This will create a new Diagnostics object if one does not already exist
@@ -63,7 +61,7 @@ def subkey(self, key: str) -> Diagnostics:
6361 The Diagnostics object for the specified subkey.
6462 """
6563 if key not in self ._subkeys :
66- self ._subkeys [key ] = Diagnostics ()
64+ self ._subkeys [key ] = type ( self ) ()
6765 return self ._subkeys [key ]
6866
6967 @contextmanager
0 commit comments