← index #1090PR #390
Related · high · value 2.178
QUERY · ISSUE

Deepcopy does not work , copied Copy from here. Can not copy Instances - Error: un(deep)copyable object of type <class 'counterObject'>. Simple examples do NOT work.

openby jlsiliconopened 2026-03-02updated 2026-03-22

Deepcopy does not work.
Using Thonny Micropython on PICO.
Copy.py is NOT on the UF2 file for PICO - as much as the docs seem to reflect.
Copied Copy.py from site here.

Can not copy Instances :
Error: un(deep)copyable object of type <class 'counterObject'>

Simple examples do NOT work.

If Standard documented Features / Cmds don't work here , then what good is the MicroPython ???

I have invested in using this for Programs for robots that I build.
So far the OOPS Objects Structuring here - is pretty much Trash - without the ability to copy Objects.

  • JAVA has no problem with this, what's the Problem here ???

StackOverflow ex :
https://stackoverflow.com/questions/42143461/make-copy-of-object-instance-in-python

class counterObject:

def __init__(self):
self.Value = 0

def incrementValue(self):
self.Value += 1

def printValue(self):
print(self.Value)

A = counterObject()
A.incrementValue()
A.printValue() ##Prints 1

import copy

B = copy.deepcopy(A)

## => Error: un(deep)copyable object of type <class 'counterObject'>

print( id(A), id(B) )


Even the Google example does not work :
https://www.google.com/search?q=micropython+howto+create+object+then+copy+object

This returns :
=> Error: un(deep)copyable object of type <class 'MyClass'>

How to Create an ObjectYou define a class and then create an instance (object) of that class by calling the class name as a function.python

class MyClass:
def __init__(self, name, value):
[self.name](http://self.name/) = name
self.value = value

## Create an object (instance of the class)
original_object = MyClass("example", 100)
  1. Deep Copy (copy.deepcopy())A deep copy creates a completely independent clone of the original object, including recursively copying all nested objects and data structures. Changes to the copy will not affect the original.
import copy

## Create a deep copy
deep_copied_object = copy.deepcopy(original_object)

## => Error: un(deep)copyable object of type <class 'MyClass'>


2 comments
jlsilicon · 2026-03-02

Simply speaking the OOPS side on this Micropython for PICO - is just Useless Trash.

-- Not functional - Right ???

I have to write my own Object Handler to work around this Failure ? - Are you kidding me ??
-- This is sad !

Think some time, you could actually Finish Code and Post code - that actually Works ???

agatti · 2026-03-22

The copy.deepcopy function attempts to duplicate an object using several different ways, returning the error you see if no attempts were successful. Most of these depend on methods that are automatically added to objects at creation time by CPython itself (eg. __reduce__). MicroPython does not add these methods to object instances to minimise the footprint of the interpreter binary and of the in-memory representation of the instances themselves, since one may argue that object deep copies are sort of an anti-pattern for memory-constrained environments. The implementation of the copy module you find in this repo is almost identical as the one you may find in your CPython's sys.path, to maintain compatibility with existing code that may leverage those extra extension points to customise the new object creation process.

If copy.deepcopy is indeed the only way to solve your issue, you can always provide your own __deepcopy__ implementation for your class, as described in CPython's copy module documentation.

I agree this limitation should have probably been added to either MicroPython's documentation or in a README.md file inside the copy module's directory in the first place (a PR is coming up soon after this), but the wording of the issue in question could have been so much better.

CANDIDATE · PULL REQUEST

copy: Add support for OrderedDict in deepcopy.

closedby andrewleechopened 2020-06-15updated 2025-11-19

(no description)

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied