Skip to content

Commit d1711a6

Browse files
committed
README update
1 parent 150b3c7 commit d1711a6

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

docs/readme.md

+41-5
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,55 @@ data type in brackets, e.g. `Model[list[int]]`.
9797
9898
The following creates a data model of a list of integers, and parses some data into that model:
9999
100-
```pycon exec="1" source="console"
100+
```pycon exec="1" session="greet" source="console"
101101
>>> from omnipy import Model
102102
>>> data = (123, '234', 345.0) # Note that the input data is a tuple of mixed types
103103
>>> data_as_list_of_ints = Model[list[int]](data)
104104
>>> data_as_list_of_ints # The data is now parsed into a list of integers
105105
```
106106
107-
```pycon exec="1" result="console"
108-
>>> from omnipy import Model
109-
>>> print(Model[list[int]]((123, '234', 345.0)).pretty_repr())
107+
```pycon exec="1" session="greet" result="console"
108+
>>> print(data_as_list_of_ints.pretty_repr())
110109
```
111110
112-
More text to come soon...
111+
Omnipy Models are self-constraining, meaning that they will always ensure that the data
112+
they contain is of the correct type. For example, if you try to append a string to the
113+
list of integers, it will raise an error:
114+
115+
```pycon
116+
>>> data_as_list_of_ints.append('abc') # This will raise an error
117+
```
118+
119+
```pycon exec="1" session="greet" result="console"
120+
>>> try:
121+
>>> data_as_list_of_ints.append('abc')
122+
>>> except Exception as err:
123+
>>> print(err)
124+
```
125+
126+
Importantly, Omnipy models automatically reverts to snapshots after an error occurs,
127+
allowing you to retry the operation without having to re-parse the data, continuing
128+
from where you left off. This is particularly useful when working with large dataflows,
129+
as it allows you to handle errors gracefully without losing your progress.
130+
131+
```pycon exec="1" session="greet" source="console"
132+
>>> data_as_list_of_ints
133+
```
134+
135+
```pycon exec="1" session="greet" result="console"
136+
>>> print(data_as_list_of_ints.pretty_repr())
137+
```
138+
139+
```pycon exec="1" session="greet" source="console"
140+
>>> data_as_list_of_ints.append('456')
141+
>>> data_as_list_of_ints
142+
```
143+
144+
```pycon exec="1" session="greet" result="console"
145+
>>> print(data_as_list_of_ints.pretty_repr())
146+
```
147+
148+
More to come soon...
113149
114150
## Running example scripts
115151
- Install `omnipy-examples`:

0 commit comments

Comments
 (0)