77import reprlib
88import time
99from enum import Enum
10- from types import FunctionType , MethodType
1110from typing import Any , Callable , List , Optional , Type , TypeVar , Union , cast , overload
1211
1312__all__ = ["LoggingDescriptor" ]
@@ -31,16 +30,16 @@ def _repr(o: Any) -> str:
3130
3231def get_class_that_defined_method (meth : Callable [..., Any ]) -> Optional [Type [Any ]]:
3332 if inspect .ismethod (meth ):
34- for c in inspect .getmro (cast ( MethodType , meth ) .__self__ .__class__ ):
33+ for c in inspect .getmro (meth .__self__ .__class__ ):
3534 if c .__dict__ .get (meth .__name__ ) is meth :
3635 return c
37- meth = cast ( MethodType , meth ) .__func__ # fallback to __qualname__ parsing
36+ meth = meth .__func__ # fallback to __qualname__ parsing
3837 if inspect .isfunction (meth ):
3938 class_name = meth .__qualname__ .split (".<locals>" , 1 )[0 ].rsplit ("." , 1 )[0 ]
4039 try :
4140 cls = getattr (inspect .getmodule (meth ), class_name )
4241 except AttributeError :
43- cls = cast ( FunctionType , meth ) .__globals__ .get (class_name )
42+ cls = meth .__globals__ .get (class_name )
4443 if isinstance (cls , type ):
4544 return cls
4645 return None
@@ -120,7 +119,7 @@ def __init_logger(self) -> LoggingDescriptor:
120119 if self .__func is not None :
121120
122121 if isinstance (self .__func , staticmethod ):
123- returned_logger = cast ( staticmethod , self .__func ) .__func__ ()
122+ returned_logger = self .__func .__func__ ()
124123 else :
125124 returned_logger = self .__func ()
126125
0 commit comments