pysertive
v0.0.1
PYSERTIVE : 계약 (DBC) 툴킷 별 독단적 파이썬 설계
Pysertive는 계약 (DBC) 원칙별 디자인을 구현하기위한 데코레이터를 제공하는 Python 라이브러리입니다. 코드에서 전제 조건, 사후 조건 및 불변성을 시행하는 것을 단순화합니다. Pysertive는 코드 동작 및 제약 조건을 보장하고 Python에서 안전하고 유지 관리 가능하며 강력한 소프트웨어 개발을 촉진하기위한 강력한 도구가되는 것을 목표로합니다.
Pysertive가 잘하는 것들 :
Pysertive는 단순성과 유연성을 염두에두고 설계되어 엄격한 계약 검사를 Python 코드에 쉽게 통합하여 복잡한 시스템을 디버깅하고 유지 관리하는 데 도움이됩니다.
pysertive를 설치하려면 Pip을 사용하기 만하면됩니다.
pip install pysertivePysertive를 신속하게 시작하는 방법은 다음과 같습니다.
from pysertive import pre_condition , post_condition , invariant
@ pre_condition ( lambda x : x > 0 , exception_type = ValueError , message = "Input must be positive" )
def sqrt ( x ):
return x ** 0.5
@ post_condition ( lambda result : result != None , exception_type = AssertionError , message = "Result cannot be None" )
def fetch_data ():
return { "data" : "Here is your data" }
@ invariant ( lambda self : self . balance >= 0 , exception_type = RuntimeError , message = "Insufficient funds" )
class BankAccount :
def __init__ ( self , balance ):
self . balance = balance
def deposit ( self , amount ):
self . balance += amount
def withdraw ( self , amount ):
self . balance -= amount # No need to manually check for negative balance 함수에 대한 입력이 유효한지 확인하십시오.
@ pre_condition ( lambda age : age >= 18 , exception_type = ValueError , message = "Must be 18 or older" )
def sign_contract ( age ):
print ( f"Contract signed by individual aged { age } " )기능이 실행 된 후 출력 유효성 :
@ post_condition ( lambda result : result > 0 , exception_type = AssertionError , message = "Profit must be positive" )
def calculate_profit ( revenue , costs ):
return revenue - costs클래스 상태의 집행은 일관성을 유지합니다.
@ invariant ( lambda self : self . inventory_count >= 0 , exception_type = RuntimeError , message = "Inventory count cannot be negative" )
class Warehouse :
def __init__ ( self , inventory_count ):
self . inventory_count = inventory_count
def add_stock ( self , number ):
self . inventory_count += number
def remove_stock ( self , number ):
self . inventory_count -= number Pysertive 사용 방법에 대한 자세한 예제는 리포지토리에서 examples.py 파일을 확인하십시오. 이 파일에는 Python 코드에서 전제 조건, 사후 조건 및 불변을 사용하는 방법에 대한 예가 포함되어 있습니다.
기부금을 환영합니다! 기여하려면 기고 가이드를 확인하고 문제 또는 풀 요청을 자유롭게 열어주십시오.
Pysertive는 MIT 라이센스에 따라 릴리스됩니다. 자세한 내용은 라이센스 파일을 참조하십시오.
위로 가십시오