나는 많은 자손 클래스에서 많은 메소드의 데코레이터 역할을하는 @classmethod
을 가진 기본 클래스를가집니다. 나는이 코드를 프로파일 및 트리보기를 통해 볼 때파이썬 cProfile - 프로파일 시각화를 모호하게하는 함수
class BaseClass():
@classmethod
def some_decorator(cls, method):
@wraps(method)
def inner_method(self, *args, **kwargs):
# do stuff
return method(self, *args, **kwargs)
return inner_method
class ChildClass(BaseClass):
@BaseClass.some_decorator
def some_child_method(self):
# do other stuff
return
, 나는 다른 장소의 수백 some_decorator
에 대한 호출의 수천을 참조하십시오.
그리고 나서 some_decorator
이 방금 나온 수백 개의 장소로 전화를 겁니다.
코드를 변경하거나 다른 방식으로 프로파일을 적용하는 방법을 찾아 내지 못했습니다. (gprof2dot atm 사용 : How can you get the call tree with python profilers?)
생각 하시겠습니까?
이 장식은 일반적으로 각 장식 기능에 대한 폐쇄를하게 때문에 당신이 업데이트 할 수 없습니다 (또는 사본을) 코드 파일 및 라인 정보를 데코 레이팅 된 함수 위에있는 라인을 참조하도록 변경 하시겠습니까? –