Commit 39acb51
authored
Use ".value" in expr.to_python() and more often (#1417)
Make use of the ".value" field in BaseElement objects, especially
Expression.to_python().
Recall, the parser creates Python equivalents for certain literal
values. In particular, a list of strings. For this, a Python tuple of
`str` appears. And this kind of thing happens a lot. And note that in
contrast to Mathics3 strings, a Python string can be duplicated. So by
using `.value` of strings found in parsing, we are not only saving time
in creation by not copying, but also memory. And we save time in
`to_python()` access as well. In some cases, like datetime objects, we
can just skip `to_python()` and use `.value` instead.
This motivation for this came from a desire to do a similar thing for
SymPy and NumPy expressions, but that will have to wait.
In the parser, list element literals are `tuple` types, whereas
`to_python ()` returns `lists`. In the places where a Python list for a
literal was expected, we have a Python tuple for the literal. In these
cases, the code has been adjusted to allow both tuple and list types.
Where certain list-only operations like mutation were needed, tuples are
converted to lists in a new variable.
Methods in module `mathics.core.atoms` have been put in alphabetical
order. A bug in `convert_expression_elements` in setting `.value` was
fixed. I suspect it wasn't noticed before because we were not making use
of `.value`.
Some of the `FilePrint` error messages have been aligned better for
WMA's (and this makes the errors clearer, too.)1 parent 454610e commit 39acb51
21 files changed
Lines changed: 611 additions & 597 deletions
File tree
- mathics
- builtin
- directories
- file_operations
- files_io
- forms
- list
- numbers
- core
- convert
- eval
- drawing
- files_io
- test
- builtin/files_io
- core
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
| 100 | + | |
110 | 101 | | |
111 | 102 | | |
112 | 103 | | |
113 | 104 | | |
114 | 105 | | |
115 | 106 | | |
116 | 107 | | |
117 | | - | |
118 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
119 | 112 | | |
120 | 113 | | |
121 | 114 | | |
| |||
249 | 242 | | |
250 | 243 | | |
251 | 244 | | |
252 | | - | |
| 245 | + | |
253 | 246 | | |
254 | 247 | | |
255 | 248 | | |
| |||
258 | 251 | | |
259 | 252 | | |
260 | 253 | | |
261 | | - | |
| 254 | + | |
262 | 255 | | |
263 | 256 | | |
264 | 257 | | |
| |||
289 | 282 | | |
290 | 283 | | |
291 | 284 | | |
292 | | - | |
| 285 | + | |
293 | 286 | | |
294 | 287 | | |
295 | 288 | | |
296 | 289 | | |
297 | 290 | | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
298 | 295 | | |
299 | 296 | | |
300 | 297 | | |
| |||
389 | 386 | | |
390 | 387 | | |
391 | 388 | | |
392 | | - | |
| 389 | + | |
393 | 390 | | |
394 | 391 | | |
395 | 392 | | |
| |||
487 | 484 | | |
488 | 485 | | |
489 | 486 | | |
490 | | - | |
491 | | - | |
| 487 | + | |
| 488 | + | |
492 | 489 | | |
493 | 490 | | |
494 | 491 | | |
| |||
497 | 494 | | |
498 | 495 | | |
499 | 496 | | |
500 | | - | |
501 | | - | |
| 497 | + | |
| 498 | + | |
502 | 499 | | |
503 | 500 | | |
504 | 501 | | |
| |||
517 | 514 | | |
518 | 515 | | |
519 | 516 | | |
520 | | - | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
521 | 520 | | |
522 | 521 | | |
523 | 522 | | |
| |||
762 | 761 | | |
763 | 762 | | |
764 | 763 | | |
765 | | - | |
| 764 | + | |
766 | 765 | | |
767 | | - | |
| 766 | + | |
768 | 767 | | |
769 | 768 | | |
770 | 769 | | |
| |||
779 | 778 | | |
780 | 779 | | |
781 | 780 | | |
782 | | - | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
783 | 786 | | |
784 | 787 | | |
785 | 788 | | |
786 | 789 | | |
787 | 790 | | |
788 | | - | |
| 791 | + | |
789 | 792 | | |
790 | 793 | | |
791 | 794 | | |
| |||
940 | 943 | | |
941 | 944 | | |
942 | 945 | | |
| 946 | + | |
943 | 947 | | |
944 | 948 | | |
945 | 949 | | |
946 | 950 | | |
947 | 951 | | |
948 | | - | |
| 952 | + | |
949 | 953 | | |
950 | 954 | | |
951 | | - | |
| 955 | + | |
952 | 956 | | |
953 | 957 | | |
954 | 958 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
| 181 | + | |
180 | 182 | | |
181 | | - | |
| 183 | + | |
| 184 | + | |
182 | 185 | | |
183 | | - | |
184 | 186 | | |
185 | | - | |
186 | | - | |
187 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
188 | 193 | | |
189 | 194 | | |
190 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | 15 | | |
17 | | - | |
18 | 16 | | |
19 | 17 | | |
20 | | - | |
21 | | - | |
| 18 | + | |
22 | 19 | | |
23 | 20 | | |
24 | 21 | | |
| |||
103 | 100 | | |
104 | 101 | | |
105 | 102 | | |
106 | | - | |
107 | | - | |
108 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
109 | 112 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 113 | + | |
117 | 114 | | |
118 | 115 | | |
119 | 116 | | |
| |||
299 | 296 | | |
300 | 297 | | |
301 | 298 | | |
302 | | - | |
| 299 | + | |
303 | 300 | | |
304 | 301 | | |
305 | 302 | | |
| |||
311 | 308 | | |
312 | 309 | | |
313 | 310 | | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
| 311 | + | |
328 | 312 | | |
329 | 313 | | |
330 | 314 | | |
331 | 315 | | |
332 | | - | |
| 316 | + | |
| 317 | + | |
333 | 318 | | |
334 | 319 | | |
335 | 320 | | |
| |||
338 | 323 | | |
339 | 324 | | |
340 | 325 | | |
341 | | - | |
342 | | - | |
343 | | - | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
344 | 329 | | |
345 | 330 | | |
346 | 331 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
270 | | - | |
271 | | - | |
272 | | - | |
| 270 | + | |
| 271 | + | |
273 | 272 | | |
274 | 273 | | |
275 | 274 | | |
| |||
281 | 280 | | |
282 | 281 | | |
283 | 282 | | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
284 | 288 | | |
| 289 | + | |
285 | 290 | | |
286 | 291 | | |
287 | 292 | | |
288 | 293 | | |
289 | 294 | | |
290 | | - | |
| 295 | + | |
291 | 296 | | |
292 | | - | |
| 297 | + | |
293 | 298 | | |
294 | 299 | | |
295 | 300 | | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
| 301 | + | |
301 | 302 | | |
302 | | - | |
| 303 | + | |
303 | 304 | | |
304 | 305 | | |
305 | 306 | | |
306 | | - | |
| 307 | + | |
307 | 308 | | |
308 | 309 | | |
309 | 310 | | |
310 | | - | |
| 311 | + | |
311 | 312 | | |
312 | 313 | | |
313 | 314 | | |
| |||
1374 | 1375 | | |
1375 | 1376 | | |
1376 | 1377 | | |
1377 | | - | |
| 1378 | + | |
1378 | 1379 | | |
1379 | 1380 | | |
1380 | | - | |
| 1381 | + | |
1381 | 1382 | | |
1382 | 1383 | | |
1383 | 1384 | | |
1384 | | - | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
1385 | 1391 | | |
1386 | 1392 | | |
1387 | 1393 | | |
1388 | | - | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
1389 | 1398 | | |
1390 | 1399 | | |
1391 | 1400 | | |
| |||
0 commit comments