From a5c57efae3f07df7c59b050edce9318818078896 Mon Sep 17 00:00:00 2001 From: Daniel McGregor Date: Thu, 15 Aug 2024 14:58:23 +0800 Subject: [PATCH] fix: use correct return type for `algopy.op.gaid` BREAKING CHANGE: `algop.op.gaid` return type has changed from `algopy.Application` to `algopy.UInt64` as the return value could be the id of either an application or an asset. Any existing usages of `algopy.op.gaid` will need to pass the result to either `algopy.Application` or `algopy.Asset` as appropriate --- langspec.puya.json | 4 ++-- scripts/transform_lang_spec.py | 8 -------- src/puya/awst_build/intrinsic_data.py | 2 +- src/puya/compile.py | 2 +- src/puya/ir/avm_ops.py | 5 ++--- stubs/algopy-stubs/op.pyi | 2 +- stubs/pyproject.toml | 2 +- 7 files changed, 8 insertions(+), 17 deletions(-) diff --git a/langspec.puya.json b/langspec.puya.json index 4a130841fd..2cf952cc0e 100644 --- a/langspec.puya.json +++ b/langspec.puya.json @@ -4183,7 +4183,7 @@ "stack_outputs": [ { "name": "X", - "stack_type": "application", + "stack_type": "uint64", "doc": null } ] @@ -4217,7 +4217,7 @@ "stack_outputs": [ { "name": "X", - "stack_type": "application", + "stack_type": "uint64", "doc": null } ] diff --git a/scripts/transform_lang_spec.py b/scripts/transform_lang_spec.py index 3a665cd231..f7c656222e 100755 --- a/scripts/transform_lang_spec.py +++ b/scripts/transform_lang_spec.py @@ -269,14 +269,6 @@ def _patch_lang_spec(lang_spec: dict[str, typing.Any]) -> None: }.items(): _patch_arg_type(ops, op_name, arg_index, "uint64", "application") - # patch ops that use a stack type of uint64 - # for return types that should be an Application - for op_name in [ - "gaid", - "gaids", - ]: - _patch_return_type(ops, op_name, 0, "uint64", "application") - # patch ops that use a stack type of uint64 # for return types that should be a bool for op_name in [ diff --git a/src/puya/awst_build/intrinsic_data.py b/src/puya/awst_build/intrinsic_data.py index 725492ae04..93a99a8b82 100644 --- a/src/puya/awst_build/intrinsic_data.py +++ b/src/puya/awst_build/intrinsic_data.py @@ -325,7 +325,7 @@ ], ), gaid=OpMappingWithOverloads( - result=pytypes.ApplicationType, + result=pytypes.UInt64Type, arity=1, overloads=[ FunctionOpMapping( diff --git a/src/puya/compile.py b/src/puya/compile.py index 0fda8a1572..cade18fa73 100644 --- a/src/puya/compile.py +++ b/src/puya/compile.py @@ -62,7 +62,7 @@ # this should contain the lowest version number that this compiler does NOT support # i.e. the next minor version after what is defined in stubs/pyproject.toml:tool.poetry.version -MAX_SUPPORTED_ALGOPY_VERSION_EX = version.parse("1.4.0") +MAX_SUPPORTED_ALGOPY_VERSION_EX = version.parse("2.1.0") MIN_SUPPORTED_ALGOPY_VERSION = version.parse(f"{MAX_SUPPORTED_ALGOPY_VERSION_EX.major}.0.0") logger = log.get_logger(__name__) diff --git a/src/puya/ir/avm_ops.py b/src/puya/ir/avm_ops.py index fb941d826f..13effc44e8 100644 --- a/src/puya/ir/avm_ops.py +++ b/src/puya/ir/avm_ops.py @@ -1657,8 +1657,7 @@ def get_variant(self, immediates: Sequence[str | int]) -> Variant: gaid = AVMOpData( op_code="gaid", variants=Variant( - signature=OpSignature(args=[], returns=[StackType.application]), - supported_modes=RunMode.app, + signature=OpSignature(args=[], returns=[StackType.uint64]), supported_modes=RunMode.app ), immediate_types=(ImmediateKind.uint8,), cost=1, @@ -1675,7 +1674,7 @@ def get_variant(self, immediates: Sequence[str | int]) -> Variant: gaids = AVMOpData( op_code="gaids", variants=Variant( - signature=OpSignature(args=[StackType.uint64], returns=[StackType.application]), + signature=OpSignature(args=[StackType.uint64], returns=[StackType.uint64]), supported_modes=RunMode.app, ), immediate_types=(), diff --git a/stubs/algopy-stubs/op.pyi b/stubs/algopy-stubs/op.pyi index db8c22a3a2..d948ba1ac8 100644 --- a/stubs/algopy-stubs/op.pyi +++ b/stubs/algopy-stubs/op.pyi @@ -244,7 +244,7 @@ def extract_uint64(a: Bytes | bytes, b: UInt64 | int, /) -> UInt64: Native TEAL opcode: [`extract_uint64`](https://developer.algorand.org/docs/get-details/dapps/avm/teal/opcodes/v10/#extract_uint64) """ -def gaid(a: UInt64 | int, /) -> Application: +def gaid(a: UInt64 | int, /) -> UInt64: """ ID of the asset or application created in the Ath transaction of the current group `gaids` fails unless the requested transaction created an asset or application and A < GroupIndex. diff --git a/stubs/pyproject.toml b/stubs/pyproject.toml index 5dd894d22b..4ae8b80bdd 100644 --- a/stubs/pyproject.toml +++ b/stubs/pyproject.toml @@ -3,7 +3,7 @@ name = "algorand-python" # this version represents the version of the stub API's and should follow semver semantics # when updating this value also update src/compile.py:MAX_SUPPORTED_ALGOPY_VERSION_EX if it is a major/minor change # also see stubs/README.md#versioning -version = "1.3.0" +version = "2.0.0" description = "API for writing Algorand Python Smart contracts" authors = ["Algorand Foundation "] readme = "README.md"