Skip to content

Commit

Permalink
docs: native import syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoCentonze committed Mar 9, 2024
1 parent 70fbb93 commit 9bd743d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
3 changes: 0 additions & 3 deletions docs/source/overview.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



Overview
========

Expand Down
35 changes: 35 additions & 0 deletions docs/source/test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,41 @@ Finally, ``coverage.py`` saves coverage data to a file named ``.coverage`` in th

Coverage is experimental and there may be odd corner cases! If so, please report them on github or in the ``#titanoboa-interpreter`` channel of the `Vyper discord <https://discord.gg/6tw7PTM7C2>`_.

Native Import Syntax
--------------------

Titanoboa supports the native Python import syntax for Vyper contracts. This means that you can import Vyper contracts in any Python script as if you were importing a Python module.

For example, if you have a contract ``contracts/Foo.vy``:

.. code-block:: vyper
x: public(uint256)
def __init__(x_initial: uint256):
self.x = x_initial
You can import it in a Python script ``tests/bar.py`` like this


.. code-block:: python
from contracts import Foo
my_contract = Foo(42) # This will create a new instance of the contract
my_contract.x() # Do anything with the contract as you normally would
Internally this will use the ``importlib`` module to load the file and create a ``ContractFactory``.


.. note::

For this to work ``boa`` must be imported first.

Due to limitations in the Python import system, only imports of the form ``import Foo`` or ``from <folder> import Foo`` will work and it is not possible to use ``import <folder>``.


Fast mode
---------

Expand Down

0 comments on commit 9bd743d

Please sign in to comment.