lineabuiltins
l_dict(*keys_and_values)
¶
Build a dict from a number of key value pairs.
There is a special case for dictionary unpacking. In this case, the key will be an instance of _DictKwargsSentinel.
For example, if the user creates a dict like {1: 2, **d, 3: 4}
,
then it will create a call like:
l_dict((1, 2), (l_dict_kwargs_sentinel(), d), (3, 4))
We use a sentinel value instead of None, because None can be a valid dictionary key.
Source code in lineapy/utils/lineabuiltins.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
l_exec_expr(code)
¶
Executes code expressions. These typically are ast nodes that inherit from ast.expr. Examples include ast.ListComp, ast.Lambda
Execute the code
with input_locals
set as locals,
and returns a list of the output_locals
pulled from the environment.
Returns:
Type | Description |
---|---|
object
|
Result as well as the last argument. |
Source code in lineapy/utils/lineabuiltins.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
l_exec_statement(code)
¶
Executes code statements. These typically are ast nodes that inherit from ast.stmt. Examples include ast.ClassDef, ast.If, ast.For, ast.FunctionDef, ast.While, ast.Try, ast.With
Execute the code
with input_locals
set as locals,
and returns a list of the output_locals
pulled from the environment.
Returns:
Type | Description |
---|---|
None
|
Since the code is a statement, it will not return anything. |
Source code in lineapy/utils/lineabuiltins.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
l_import(name, base_module=None)
¶
Imports and returns a module. If the base_module is provided, the module will be a submodule of the base.
If a base_module
is provided, the base_module will be flagged as 'mutated' by our annotations.
Source code in lineapy/utils/lineabuiltins.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
l_unpack_ex(xs, before, after)
¶
Slits the iterable xs
into three pieces and then joins them [*first, middle, *list]
The first of length before
, the last of length after
, and the middle whatever is remaining.
Modeled after the UNPACK_EX bytecode to be used in unpacking.
Source code in lineapy/utils/lineabuiltins.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
l_unpack_sequence(xs, n)
¶
Asserts the iterable xs
is of length n
and turns it into a list.
The same as l_list
but asserts the length. This was modeled after the UNPACK_SEQUENCE
bytecode to be used in unpacking
The result should be a view of the input.
Source code in lineapy/utils/lineabuiltins.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|