From 9dc19e1388857dff8e3da96069a4c05fa674d3ce Mon Sep 17 00:00:00 2001 From: Dalena Date: Fri, 23 Aug 2024 11:34:37 -0500 Subject: [PATCH] docs: add convert examples (#2241) --- docs/methoddocs/api.md | 1 + src/ape/api/convert.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/docs/methoddocs/api.md b/docs/methoddocs/api.md index 4a7c268766..3062550f37 100644 --- a/docs/methoddocs/api.md +++ b/docs/methoddocs/api.md @@ -40,6 +40,7 @@ .. automodule:: ape.api.convert :members: :show-inheritance: + :special-members: ``` ## Explorers diff --git a/src/ape/api/convert.py b/src/ape/api/convert.py index b60a05970f..eb85aa5c89 100644 --- a/src/ape/api/convert.py +++ b/src/ape/api/convert.py @@ -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' + """