Modules

array

Comparison between different typecodes not supported

Cause: Code size

Workaround: Compare individual elements

Sample code:

import array

array.array("b", [1, 2]) == array.array("i", [1, 2])
CPy output: uPy output:
 
Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
NotImplementedError:

Looking for integer not implemented

Sample code:

import array

print(1 in array.array("B", b"12"))
CPy output: uPy output:
False
Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
NotImplementedError:

Array deletion not implemented

Sample code:

import array

a = array.array("b", (1, 2, 3))
del a[1]
print(a)
CPy output: uPy output:
array('b', [1, 3])
Traceback (most recent call last):
  File "<stdin>", line 10, in <module>
TypeError: 'array' object doesn't support item deletion

Subscript with step != 1 is not yet implemented

Sample code:

import array

a = array.array("b", (1, 2, 3))
print(a[3:2:2])
CPy output: uPy output:
array('b')
Traceback (most recent call last):
  File "<stdin>", line 10, in <module>
NotImplementedError: only slices with step=1 (aka None) are supported

builtins

Second argument to next() is not implemented

Cause: Pycopy is optimised for code space.

Workaround: Instead of val = next(it, deflt) use:

try:
    val = next(it)
except StopIteration:
    val = deflt

Sample code:

print(next(iter(range(0)), 42))
CPy output: uPy output:
42
Traceback (most recent call last):
  File "<stdin>", line 12, in <module>
TypeError: function takes 1 positional arguments but 2 were given

collections

Only minimal deque functionality is implemented

Cause: Builtin deques are intended for efficient, zero-allocation queuing, and thus are fixed-size and provide only .append() and .popleft() methods.

Workaround: Use regular lists. pycopy-lib provides full implementation of collections.deque.

Sample code:

import collections

D = collections.deque()
print(D)
CPy output: uPy output:
deque([])
Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
TypeError: function missing 2 required positional arguments

json

JSON module does not throw exception when object is not serialisable

Sample code:

import json

a = bytes(x for x in range(256))
try:
    z = json.dumps(a)
    x = json.loads(z)
    print("Should not get here")
except TypeError:
    print("TypeError")
CPy output: uPy output:
TypeError
Should not get here

struct

Struct pack with too few args, not checked by uPy

Sample code:

import struct

try:
    print(struct.pack("bb", 1))
    print("Should not get here")
except:
    print("struct.error")
CPy output: uPy output:
struct.error
b'\x01\x00'
Should not get here

Struct pack with too many args, not checked by uPy

Sample code:

import struct

try:
    print(struct.pack("bb", 1, 2, 3))
    print("Should not get here")
except:
    print("struct.error")
CPy output: uPy output:
struct.error
b'\x01\x02'
Should not get here

sys

Overriding sys.stdin, sys.stdout and sys.stderr not possible

Cause: They are stored in read-only memory.

Sample code:

import sys

sys.stdin = None
print(sys.stdin)
CPy output: uPy output:
None
Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
AttributeError: 'module' object has no attribute 'stdin'