Morgan243 / python-on-a-chip

Automatically exported from code.google.com/p/python-on-a-chip
Other
0 stars 0 forks source link

Add support to iterate over keys in a dict #176

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Report from Oscar on maillist on 2010/12/25:

This program:
d = {1: 'a', 2: 'b'}
print d
print 3 in d
print 2 in d
for i in d:
   print i

Has this output when run in cpython
{1: 'a', 2: 'b'}
False
True
1
2

In pymite (desktop platform) I get this:
{2:'b', 1:'a'}
False
True
Traceback (most recent call first):
 File "all_tests.py", line 11, in all_tests
TypeError detected by seq.c:254

Original issue reported on code.google.com by dwhall...@gmail.com on 26 Dec 2010 at 4:04

GoogleCodeExporter commented 8 years ago

Original comment by dwhall...@gmail.com on 26 Dec 2010 at 10:58

GoogleCodeExporter commented 8 years ago
As a side effect, this Python feature can be added because PyMite's 
UNPACK_SEQUENCE bytecode calls seq_getSubscript, which will now accept dict 
types:

>>> d = {1: 'one', 2: 'two'}
>>> m,n = d
>>> n
2
>>> m
1

Original comment by dwhall...@gmail.com on 26 Dec 2010 at 11:04

GoogleCodeExporter commented 8 years ago
As a side effect, this Python feature can be added because PyMite's sum() 
builtin function calls seq_getSubscript, which will now accept dict types:

>>> d = {1: 'one', 2: 'two'}
>>> sum(d)
3

Original comment by dwhall...@gmail.com on 26 Dec 2010 at 11:06

GoogleCodeExporter commented 8 years ago
Also adding bytearray to the types that can be passed to __bi.sum().

Original comment by dwhall...@gmail.com on 27 Dec 2010 at 2:05

GoogleCodeExporter commented 8 years ago
Minor changes:
- Changed t377 comment to say 377
- Changed some python object structures' length field from int16_t to uint16_t 
for uniformity.

Original comment by dwhall...@gmail.com on 27 Dec 2010 at 2:58

GoogleCodeExporter commented 8 years ago
r716cef81d103

Mainlined directly.  Tests pass.

Original comment by dwhall...@gmail.com on 27 Dec 2010 at 3:03