Skip to content

Commit

Permalink
fix: metadata output interaction with natspec
Browse files Browse the repository at this point in the history
enabling the `-f metadata` output has an interaction with other outputs
because the metadata output format mutates some internal data structures
in-place. this is because `vars()` returns a reference to the object's
`__dict__` as opposed to a copy of it. the behavior can be seen by
trying to call the compiler with `-f metadata,devdoc,userdoc`.

this commit fixes the issue by constructing a copy of the object during
metadata output formatting. it also modifies the test suite to include
more output formats, to test the interactions between these different
output formats. in doing so, it was also found that some examples have
invalid natspec, which has also been fixed.
  • Loading branch information
charles-cooper committed Sep 28, 2023
1 parent 2bdbd84 commit ed8a058
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
2 changes: 0 additions & 2 deletions examples/tokens/ERC1155ownable.vy
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ def mint(receiver: address, id: uint256, amount:uint256):
@param receiver the account that will receive the minted token
@param id the ID of the token
@param amount of tokens for this ID
@param data the data associated with this mint. Usually stays empty
"""
assert not self.paused, "The contract has been paused"
assert self.owner == msg.sender, "Only the contract owner can mint"
Expand All @@ -232,7 +231,6 @@ def mintBatch(receiver: address, ids: DynArray[uint256, BATCH_SIZE], amounts: Dy
@param receiver the account that will receive the minted token
@param ids array of ids for the tokens
@param amounts amounts of tokens for each ID in the ids array
@param data the data associated with this mint. Usually stays empty
"""
assert not self.paused, "The contract has been paused"
assert self.owner == msg.sender, "Only the contract owner can mint"
Expand Down
4 changes: 2 additions & 2 deletions tests/base_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def _get_contract(w3, source_code, optimize, *args, override_opt_level=None, **k
settings.optimize = override_opt_level or optimize
out = compiler.compile_code(
source_code,
# test that metadata gets generated
["abi", "bytecode", "metadata"],
# test that metadata and natspecs get generated
["abi", "bytecode", "metadata", "userdoc", "devdoc"],
settings=settings,
interface_codes=kwargs.pop("interface_codes", None),
show_gas_estimates=True, # Enable gas estimates for testing
Expand Down
2 changes: 1 addition & 1 deletion vyper/compiler/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _var_rec_dict(variable_record):
return ret

def _to_dict(func_t):
ret = vars(func_t)
ret = vars(func_t).copy()
ret["return_type"] = str(ret["return_type"])
ret["_ir_identifier"] = func_t._ir_info.ir_identifier

Expand Down

0 comments on commit ed8a058

Please sign in to comment.