typeguard_jupiter
Python 2.7 ve Python 3.x uyumlu, çalışma zamanında (runtime) tip kontrolü yapan basit bir dekoratör paketi.
Kurulum
Sanal ortamı (venv) aktif ettikten sonra pip ile kurabilirsiniz:
pip install .
Derlenmiş universal wheel (.whl, Python 2 ve Python 3 ortak) dosyasından kurmak için:
pip install dist/typeguard_jupiter-0.1.0-py2.py3-none-any.whl
PyPI'ya yüklendikten sonra:
pip install typeguard_jupiter
Kullanım
Python 2 ve Python 3 Ortak Kullanım
from __future__ import print_function
from typeguard_jupiter import TypeGuard, WrongTypeAnnotationError
@TypeGuard(label="Custom Type Guard", x=int, y=int)
def add(x, y):
return x + y
try:
print(add(x=6, y="Canbula"))
except WrongTypeAnnotationError as e:
print("Hata: {0}".format(e))
Python 3 Type Annotation ile Kullanım
from typeguard_jupiter import TypeGuard
@TypeGuard(label="Custom Type Guard")
def add(*, x: int, y: int) -> int:
return x + y
Demo betiğini çalıştırmak için:
python -m typeguard_jupiter
# veya
typeguard-jupiter-demo