Skip to content

Commit c1f74b3

Browse files
spon-wwdpgeorge
authored andcommitted
docs/library: Warn that ustruct doesn't handle spaces in format strings.
And also add a test to capture the CPython difference.
1 parent d934f8c commit c1f74b3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

docs/library/ustruct.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ Supported format codes: ``b``, ``B``, ``h``, ``H``, ``i``, ``I``, ``l``,
1212
``L``, ``q``, ``Q``, ``s``, ``P``, ``f``, ``d`` (the latter 2 depending
1313
on the floating-point support).
1414

15+
.. admonition:: Difference to CPython
16+
:class: attention
17+
18+
Whitespace is not supported in format strings.
19+
1520
Functions
1621
---------
1722

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
categories: Modules,struct
3+
description: Struct pack with whitespace in format, whitespace ignored by CPython, error on uPy
4+
cause: MicroPython is optimised for code size.
5+
workaround: Don't use spaces in format strings.
6+
"""
7+
import struct
8+
9+
try:
10+
print(struct.pack('b b', 1, 2))
11+
print('Should have worked')
12+
except:
13+
print('struct.error')

0 commit comments

Comments
 (0)