Skip to content

Commit 8b2e1e5

Browse files
authored
Update imports.md
1 parent 7134b9e commit 8b2e1e5

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

docs/concepts/imports.md

+29-29
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The simplest use-case for imports is wanting to call a function that is an `@exp
44

55
__NOTE:__ `from x import y` and starred imports are not supported at this time. Importing a smart contract imports all of the `@export` functions from it and none of the variables.
66

7-
complex_app
7+
complex_app.py
88
```python
99
@export
1010
def return_1():
@@ -19,7 +19,7 @@ def return_3():
1919
return 3
2020
```
2121

22-
import_example
22+
import_example.py
2323
```python
2424
import complex_app
2525

@@ -43,7 +43,7 @@ To do this, we have to use the `importlib` in the Contracting standard library.
4343

4444
This function behaves similar to the analogous `importlib` function included in the Python standard library. Calling it will return a module object that has only the `@export` functions available to call and pass arguments to.
4545

46-
token_1
46+
token_1.py
4747
```python
4848
balances = Hash()
4949
@construct
@@ -58,7 +58,7 @@ def send(amount, to):
5858
balances[to] += amount
5959
```
6060

61-
token_2
61+
token_2.py
6262
```python
6363
balances = Hash()
6464
@construct
@@ -73,7 +73,7 @@ def send(amount, to):
7373
balances[to] += amount
7474
```
7575

76-
exchange
76+
exchange.py
7777
```python
7878
@export
7979
def send(token, amount, to):
@@ -87,7 +87,7 @@ Luckily, both contracts have the same interface and have a function called `send
8787

8888
A smart contract can define an interface to enforce contracts against. Enforcement can be on the functions and/or the variables. Enforcement is 'weak' in the sense that a contract can have additional functions or variables and still succeed an interface test.
8989

90-
exchange
90+
exchange.py
9191
```python
9292
token_interface = [
9393
importlib.Func('send', args=('amount', 'to')),
@@ -118,21 +118,21 @@ A variable definition for the name, a string, and the type, which is either Vari
118118

119119
```python
120120
interface_1 = [
121-
importlib.Func('something', private=True)
121+
importlib.Func('something', private=True)
122122
]
123123

124124
def valid_contract():
125-
def something(): # Correct name and private
126-
return 123
125+
def something(): # Correct name and private
126+
return 123
127127

128-
@export
129-
def something_else():
130-
return 456
128+
@export
129+
def something_else():
130+
return 456
131131

132132
def invalid_contract():
133-
@export
134-
def something(): # Correct name, but exported
135-
return 123
133+
@export
134+
def something(): # Correct name, but exported
135+
return 123
136136
```
137137

138138

@@ -142,17 +142,17 @@ interface_2 = [
142142
]
143143

144144
def valid_contract():
145-
@export
146-
def func(a, b, c): # Exported function with same name and args in correct order
147-
return a + b + c
145+
@export
146+
def func(a, b, c): # Exported function with same name and args in correct order
147+
return a + b + c
148148

149149
def invalid_contract():
150-
def func(a, c, b): # Correct name, but private, and keyword arguments are out of order
151-
return a + b + c
150+
def func(a, c, b): # Correct name, but private, and keyword arguments are out of order
151+
return a + b + c
152152

153-
@export
154-
def not_func(a, b, c): # Exported and correct keyword args but not the right name
155-
return a + b + c
153+
@export
154+
def not_func(a, b, c): # Exported and correct keyword args but not the right name
155+
return a + b + c
156156
```
157157

158158
```python
@@ -162,14 +162,14 @@ interface_3 = [
162162
]
163163

164164
def valid_contract():
165-
balances = Hash()
166-
owner = Variable()
165+
balances = Hash()
166+
owner = Variable()
167167

168168
def invalid_contract():
169-
balances = Variable() # Incorrect types
170-
owner = Hash()
169+
balances = Variable() # Incorrect types
170+
owner = Hash()
171171

172172
def invalid_contract_2():
173-
bbb = Variable() # Correct types, but misspelled.
174-
ooo = Hash()
173+
bbb = Variable() # Correct types, but misspelled.
174+
ooo = Hash()
175175
```

0 commit comments

Comments
 (0)