remove generic from instrumentation

This commit is contained in:
AF 2023-01-13 15:33:49 +00:00
parent 49014b6a4d
commit d834c24e14

View File

@ -1,13 +1,13 @@
import functools import functools
from contextlib import ExitStack from contextlib import ExitStack
from typing import Callable, Generic, TypeVar from typing import Callable, TypeVar
__all__ = ('Instrumentation',) __all__ = ('Instrumentation',)
IType = TypeVar('IType') IType = TypeVar('IType', bound='Instrumentation')
class Instrumentation(Generic[IType]): class Instrumentation:
deinstrumentation = {} deinstrumentation = {}
_method: Callable _method: Callable
_wrap: Callable _wrap: Callable
@ -24,8 +24,6 @@ class Instrumentation(Generic[IType]):
raise NotImplementedError raise NotImplementedError
def __enter__(self: IType) -> IType: def __enter__(self: IType) -> IType:
if not isinstance(self, Instrumentation):
raise TypeError
if hasattr(self, '_method') or hasattr(self, '_wrap'): if hasattr(self, '_method') or hasattr(self, '_wrap'):
raise RuntimeError raise RuntimeError
method = getattr(self.target, self.methodname) method = getattr(self.target, self.methodname)