@@ -97,19 +97,55 @@ data type in brackets, e.g. `Model[list[int]]`.
97
97
98
98
The following creates a data model of a list of integers, and parses some data into that model:
99
99
100
- ` ` ` pycon exec= " 1" source= " console"
100
+ ` ` ` pycon exec= " 1" session = " greet " source= " console"
101
101
>>> from omnipy import Model
102
102
>>> data = (123, ' 234' , 345.0) # Note that the input data is a tuple of mixed types
103
103
>>> data_as_list_of_ints = Model[list[int]](data)
104
104
>>> data_as_list_of_ints # The data is now parsed into a list of integers
105
105
` ` `
106
106
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 ())
110
109
` ` `
111
110
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...
113
149
114
150
# # Running example scripts
115
151
- Install ` omnipy-examples` :
0 commit comments