.. This document was generated by tools/gen-cpydiff.py Modules ======= Generated Wed 03 Jan 2024 12:07:50 UTC array ----- .. _cpydiff_modules_array_containment: Looking for integer not implemented ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sample code:: import array print(1 in array.array("B", b"12")) +-------------+-------------------------------------------------------------------+ | CPy output: | uPy output: | +-------------+-------------------------------------------------------------------+ | :: | :: | | | | | False | /bin/sh: ../ports/unix/micropython: No such file or directory | +-------------+-------------------------------------------------------------------+ .. _cpydiff_modules_array_deletion: 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]) | /bin/sh: ../ports/unix/micropython: No such file or directory | +------------------------+-------------------------------------------------------------------+ .. _cpydiff_modules_array_subscrstep: 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') | /bin/sh: ../ports/unix/micropython: No such file or directory | +----------------+-------------------------------------------------------------------+ builtins -------- .. _cpydiff_builtin_next_arg2: Second argument to next() is not implemented ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ **Cause:** MicroPython 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 | /bin/sh: ../ports/unix/micropython: No such file or directory | +-------------+-------------------------------------------------------------------+ deque ----- .. _cpydiff_modules_deque: Deque not implemented ~~~~~~~~~~~~~~~~~~~~~ **Workaround:** Use regular lists. micropython-lib has implementation of collections.deque. Sample code:: import collections D = collections.deque() print(D) +---------------+-------------------------------------------------------------------+ | CPy output: | uPy output: | +---------------+-------------------------------------------------------------------+ | :: | :: | | | | | deque([]) | /bin/sh: ../ports/unix/micropython: No such file or directory | +---------------+-------------------------------------------------------------------+ json ---- .. _cpydiff_modules_json_nonserializable: 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 | /bin/sh: ../ports/unix/micropython: No such file or directory | +---------------+-------------------------------------------------------------------+ os -- .. _cpydiff_modules_os_environ: ``environ`` attribute is not implemented ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ **Workaround:** Use ``getenv``, ``putenv`` and ``unsetenv`` Sample code:: import os try: print(os.environ.get("NEW_VARIABLE")) os.environ["NEW_VARIABLE"] = "VALUE" print(os.environ["NEW_VARIABLE"]) except AttributeError: print("should not get here") print(os.getenv("NEW_VARIABLE")) os.putenv("NEW_VARIABLE", "VALUE") print(os.getenv("NEW_VARIABLE")) +-------------+-------------------------------------------------------------------+ | CPy output: | uPy output: | +-------------+-------------------------------------------------------------------+ | :: | :: | | | | | None | /bin/sh: ../ports/unix/micropython: No such file or directory | | VALUE | | +-------------+-------------------------------------------------------------------+ .. _cpydiff_modules_os_getenv: ``getenv`` returns actual value instead of cached value ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ **Cause:** The ``environ`` attribute is not implemented Sample code:: import os print(os.getenv("NEW_VARIABLE")) os.putenv("NEW_VARIABLE", "VALUE") print(os.getenv("NEW_VARIABLE")) +-------------+-------------------------------------------------------------------+ | CPy output: | uPy output: | +-------------+-------------------------------------------------------------------+ | :: | :: | | | | | None | /bin/sh: ../ports/unix/micropython: No such file or directory | | None | | +-------------+-------------------------------------------------------------------+ .. _cpydiff_modules_os_getenv_argcount: ``getenv`` only allows one argument ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ **Workaround:** Test that the return value is ``None`` Sample code:: import os try: print(os.getenv("NEW_VARIABLE", "DEFAULT")) except TypeError: print("should not get here") # this assumes NEW_VARIABLE is never an empty variable print(os.getenv("NEW_VARIABLE") or "DEFAULT") +-------------+-------------------------------------------------------------------+ | CPy output: | uPy output: | +-------------+-------------------------------------------------------------------+ | :: | :: | | | | | DEFAULT | /bin/sh: ../ports/unix/micropython: No such file or directory | +-------------+-------------------------------------------------------------------+ struct ------ .. _cpydiff_modules_struct_fewargs: 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 | /bin/sh: ../ports/unix/micropython: No such file or directory | +------------------+-------------------------------------------------------------------+ .. _cpydiff_modules_struct_manyargs: 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 | /bin/sh: ../ports/unix/micropython: No such file or directory | +------------------+-------------------------------------------------------------------+ sys --- .. _cpydiff_modules_sys_stdassign: 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 | /bin/sh: ../ports/unix/micropython: No such file or directory | +-------------+-------------------------------------------------------------------+