PyContract (PyContracts이 아님)을 사용하는 클래스 메소드에 대한 제약 조건을 작성하고 있습니다. 사후 조건으로 인스턴스의 메모리 주소가 변경되지 않았 음을 확인하고 싶습니다. 즉, 함수 호출 전후에 id(self)
이 동일해야합니다. 어떻게하면 PyContract로이 작업을 수행 할 수 있습니까? 나는 다음 (최소한의) 코드를 가지고 :PyContract 제약 조건에서`__old__`에서`self`를 참조하십시오
class Individual:
def append(self, chrom):
"""
post:
__old__.self is self
len(__old__.self.chromosomes)+1 == len(self.chromosomes)
self.chromosomes[-1] == chrom
"""
self.chromosomes.append(chrom)
여기 제약의 문제는 게시물에, 나는이 오류를 얻을 수 있습니다 : _holder instance has no attribute 'self'
여기서 흥미로운 것은 class Individual
가 __init__
누구의 제약을 가지고 있다는 것입니다을 다음과 같이 :
pre:
isinstance(chromosomes, list)
post[chromosomes]:
__old__.chromosomes is chromosomes
__old__.chromosomes == chromosomes
post:
hasattr(self, 'chromosomes')
self.chromosomes == chromosomes
를 지금까지 내가 말할 수있는, PyContract
내가 __old__.self
를 호출 할 것을 좋아하지 않는다. 이 문제를 어떻게 해결할 수 있습니까?