Skip to content

Commit

Permalink
fix subroutine args with no doc (#524)
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin committed Sep 7, 2022
1 parent f8911e7 commit 1cb6c97
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Unreleased

## Fixed
* ABI methods without a docstring now have their arguments in the output Contract object. ([#524](https://github.com/algorand/pyteal/pull/524))

# 0.18.0

## Added
Expand Down
32 changes: 16 additions & 16 deletions pyteal/ast/subroutine.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,22 +651,22 @@ def method_spec(self) -> sdk_abi.Method:
else docstring.returns.description.replace("\n", " ").strip()
)

# Generate the ABI method object given the subroutine args
# Add in description if one is set
for name, val in self.subroutine.annotations.items():
# Skip annotations for `return` and `output` in the args list
if name in ["return", self.OUTPUT_ARG_NAME]:
continue

arg_obj = {
"type": str(abi.type_spec_from_annotation(val)),
"name": name,
}

if name in arg_descs:
arg_obj["desc"] = arg_descs[name]

args.append(arg_obj)
# Generate the ABI method object given the subroutine args
# Add in description if one is set
for name, val in self.subroutine.annotations.items():
# Skip annotations for `return` and `output` in the args list
if name in ["return", self.OUTPUT_ARG_NAME]:
continue

arg_obj = {
"type": str(abi.type_spec_from_annotation(val)),
"name": name,
}

if name in arg_descs:
arg_obj["desc"] = arg_descs[name]

args.append(arg_obj)

# Create the return obj for the method, adding description if set
return_obj = {"type": str(self.type_of())}
Expand Down
8 changes: 7 additions & 1 deletion pyteal/ast/subroutine_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1415,10 +1415,16 @@ def documented_method(a: pt.abi.Uint64, *, output: pt.abi.Uint64):
:returns: {return_doc}
"""
mspec_dict = ABIReturnSubroutine(documented_method).method_spec().dictify()
assert "descr" not in mspec_dict
assert "desc" not in mspec_dict
assert mspec_dict["args"][0]["desc"] == a_doc
assert mspec_dict["returns"]["desc"] == return_doc

# No doc
documented_method.__doc__ = None
mspec_dict = ABIReturnSubroutine(documented_method).method_spec().dictify()
assert "desc" not in mspec_dict
assert len(mspec_dict["args"]) == 1

algobank_example = """Withdraw an amount of Algos held by this app.
The sender of this method call will be the source of the Algos, and the destination will be
Expand Down

0 comments on commit 1cb6c97

Please sign in to comment.