부모 메서드 (꾸미는 클래스의 부모에서 같은 이름의 메서드)를 검사해야하는 메서드의 데코레이터를 작성하고 있습니다. (PEP 318의 제 4 실시 예에서)데코레이터에서 데코 레이팅 된 메서드를 소유하는 클래스에 액세스
예 :
def returns(rtype):
def check_returns(f):
def new_f(*args, **kwds):
result = f(*args, **kwds)
assert isinstance(result, rtype), \
"return value %r does not match %s" % (result,rtype)
return result
new_f.func_name = f.func_name
# here I want to reach the class owning the decorated method f,
# it should give me the class A
return new_f
return check_returns
class A(object):
@returns(int)
def compute(self, value):
return value * 3
가 그래서 ... 여기
# 내가 원하는 대신에 입력 할 수있는 코드를
감사를 찾고 있어요.
내 문제는 내가 말한 것보다 훨씬 구체적이기 때문에 코드를 직접 사용하지 않았습니다. 그러나 * name *이 * type * 구조에서 일반적으로 사용되기 때문에 * dct *를 트래버스 할 때 * name *을 사용하는 것이 조금 이상합니다. 고마워, 제게 많은 도움이 되었기 때문에 어쨌든 답을 수락하는 것이 좋습니다. – Gra
아, 그게 실수 야. –