Browse Source

docs/library: Warn that ustruct doesn't handle spaces in format strings.

And also add a test to capture the CPython difference.
pull/7498/head
Tom McDermott 5 years ago
committed by Damien George
parent
commit
c1f74b3005
  1. 5
      docs/library/ustruct.rst
  2. 13
      tests/cpydiff/modules_struct_whitespace_in_format.py

5
docs/library/ustruct.rst

@ -12,6 +12,11 @@ Supported format codes: ``b``, ``B``, ``h``, ``H``, ``i``, ``I``, ``l``,
``L``, ``q``, ``Q``, ``s``, ``P``, ``f``, ``d`` (the latter 2 depending
on the floating-point support).
.. admonition:: Difference to CPython
:class: attention
Whitespace is not supported in format strings.
Functions
---------

13
tests/cpydiff/modules_struct_whitespace_in_format.py

@ -0,0 +1,13 @@
"""
categories: Modules,struct
description: Struct pack with whitespace in format, whitespace ignored by CPython, error on uPy
cause: MicroPython is optimised for code size.
workaround: Don't use spaces in format strings.
"""
import struct
try:
print(struct.pack('b b', 1, 2))
print('Should have worked')
except:
print('struct.error')
Loading…
Cancel
Save