diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml index ef632a13..cd613184 100644 --- a/.github/workflows/continuous-integration-workflow.yml +++ b/.github/workflows/continuous-integration-workflow.yml @@ -45,6 +45,12 @@ jobs: - name: Test with pytest run: poetry run pytest -v -rs tests --runslow --cov=./ --cov-report=xml + - name: Test with pytest (runtime type checking disabled) + if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.7' + run: poetry run pytest -v -rs tests --runslow + env: + STELLAR_SDK_RUNTIME_TYPE_CHECKING: 0 + - name: Upload coverage to Codecov if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.7' uses: codecov/codecov-action@v1 diff --git a/stellar_sdk/type_checked.py b/stellar_sdk/type_checked.py index d101ce90..1ac17e1f 100644 --- a/stellar_sdk/type_checked.py +++ b/stellar_sdk/type_checked.py @@ -4,9 +4,9 @@ from typeguard import T_CallableOrType from typeguard import typechecked as _typechecked -_STELLAR_SDK_ENFORCE_TYPE_CHECK_FLAG: str = "STELLAR_SDK_ENFORCE_TYPE_CHECK" -_STELLAR_SDK_ENFORCE_TYPE_CHECK: bool = os.getenv( - _STELLAR_SDK_ENFORCE_TYPE_CHECK_FLAG, "False" +_STELLAR_SDK_RUNTIME_TYPE_CHECKING_FLAG: str = "STELLAR_SDK_RUNTIME_TYPE_CHECKING" +_STELLAR_SDK_RUNTIME_TYPE_CHECKING: bool = os.getenv( + _STELLAR_SDK_RUNTIME_TYPE_CHECKING_FLAG, "True" ).lower() in ("true", "1", "t") @@ -23,4 +23,7 @@ def type_checked(func: T_CallableOrType) -> T_CallableOrType: def type_checked( func=None, ): - return _typechecked(func=func, always=_STELLAR_SDK_ENFORCE_TYPE_CHECK) + if _STELLAR_SDK_RUNTIME_TYPE_CHECKING: + return _typechecked(func=func) + else: + return func diff --git a/tests/operation/test_operation.py b/tests/operation/test_operation.py index 325af557..f0cdde7b 100644 --- a/tests/operation/test_operation.py +++ b/tests/operation/test_operation.py @@ -1,6 +1,7 @@ import pytest from stellar_sdk import Operation +from stellar_sdk.type_checked import _STELLAR_SDK_RUNTIME_TYPE_CHECKING class TestOperation: @@ -19,10 +20,14 @@ def test_to_xdr_amount(self, origin_amount, expect_value): @pytest.mark.parametrize( "origin_amount, exception, reason", [ - ( + pytest.param( 10, TypeError, 'type of argument "value" must be one of \\(str, decimal.Decimal\\); got int instead', + marks=pytest.mark.skipif( + not _STELLAR_SDK_RUNTIME_TYPE_CHECKING, + reason="runtime_type_checking_disabled", + ), ), ( "-0.1", diff --git a/tests/sep/test_stellar_uri.py b/tests/sep/test_stellar_uri.py index 270113a7..ec159027 100644 --- a/tests/sep/test_stellar_uri.py +++ b/tests/sep/test_stellar_uri.py @@ -10,6 +10,7 @@ TransactionStellarUri, ) from stellar_sdk.transaction_envelope import TransactionEnvelope +from stellar_sdk.type_checked import _STELLAR_SDK_RUNTIME_TYPE_CHECKING class TestStellarTransactionStellarUri: @@ -481,6 +482,9 @@ def test_message_too_long_raise(self): message=message, ) + @pytest.mark.skipif( + not _STELLAR_SDK_RUNTIME_TYPE_CHECKING, reason="runtime_type_checking_disabled" + ) def test_invalid_memo_raise(self): memo = "invalid memo" with pytest.raises( diff --git a/tests/sep/test_stellar_web_authentication.py b/tests/sep/test_stellar_web_authentication.py index a966438d..c610d109 100644 --- a/tests/sep/test_stellar_web_authentication.py +++ b/tests/sep/test_stellar_web_authentication.py @@ -22,6 +22,7 @@ ) from stellar_sdk.transaction_builder import TransactionBuilder from stellar_sdk.transaction_envelope import TransactionEnvelope +from stellar_sdk.type_checked import _STELLAR_SDK_RUNTIME_TYPE_CHECKING class TestStellarWebAuthentication: @@ -117,6 +118,9 @@ def test_challenge_transaction_id_memo_as_int_permitted(self): ).transaction assert transaction.memo == IdMemo(memo) + @pytest.mark.skipif( + not _STELLAR_SDK_RUNTIME_TYPE_CHECKING, reason="runtime_type_checking_disabled" + ) def test_challenge_transaction_non_id_memo_not_permitted(self): server_kp = Keypair.random() client_account_id = Keypair.random().public_key