Skip to content

Commit

Permalink
docs: add convert example
Browse files Browse the repository at this point in the history
  • Loading branch information
dtdang committed Aug 23, 2024
1 parent 078b8f2 commit 584b602
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/methoddocs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
.. automodule:: ape.api.convert
:members:
:show-inheritance:
:special-members:
```

## Explorers
Expand Down
18 changes: 18 additions & 0 deletions src/ape/api/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,22 @@ def convert(self, value: Any) -> ConvertedType:
Convert the given value to the type specified as the generic for this class.
Implementations of this API must throw a :class:`~ape.exceptions.ConversionError`
when the item fails to convert properly.
Usage example::
from ape import convert
from ape.types import AddressType
convert("1 gwei", int)
# 1000000000
convert("1 ETH", int)
# 1000000000000000000
convert("283Af0B28c62C092C9727F1Ee09c02CA627EB7F5", bytes)
# HexBytes('0x283af0b28c62c092c9727f1ee09c02ca627eb7f5')
convert("vitalik.eth", AddressType)
# '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
"""

0 comments on commit 584b602

Please sign in to comment.