Skip to content

Commit a19717b

Browse files
committed
copy: Provide top-level documentation.
This commit adds documentation for the `copy` module, explaining why the module may require some changes in the objects being copied to behave as CPython. Unlike CPython, MicroPython does not provide default implementations for either `__reduce__` or `__reduce_ex__`, which are used by the copy module as the fallback methods to create copies of non-trivial objects. These methods aren't provided by default to minimise both the footprint of the interpreter binary and the RAM taken by object instances. Users who want simpler ways to allow object copies can implement `__copy__` and `__deepcopy__` instead, as mentioned in CPython's documentation for the `copy` module. Arguably the lack of `__reduce__` and `__reduce_ex__` could also be mentioned in MicroPython's own documentation as part of the differences from CPython, but it doesn't hurt to mention more module-specific caveats in here too. This should, in theory, keep user expectations in check w.r.t. the behaviour of this specific module. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
1 parent 00efb6c commit a19717b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

python-stdlib/copy/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# copy
2+
3+
Copies of non-trivial objects on CPython depend on an implementation of
4+
``__reduce__`` or ``__reduce_ex__`` being available, with the former method
5+
being usually added by CPython itself as part of the standard object creation.
6+
MicroPython, to keep both flash and RAM footprints down, does not provide an
7+
implementation of ``__reduce__``.
8+
9+
Objects that do not provide either of those methods may implement
10+
[``__copy__``](https://docs.python.org/3/library/copy.html#object.__copy__) or
11+
[`__deepcopy__`](https://docs.python.org/3/library/copy.html#object.__deepcopy__)
12+
to allow the copy operation to succeed.

0 commit comments

Comments
 (0)