MicroPython differences from CPython¶
MicroPython implements Python 3.4 and some select features of Python 3.5 and above. The sections below describe the current status of these features.
For the features of Python that are implemented by MicroPython, there are sometimes differences in their behaviour compared to standard Python. The operations listed in the sections below produce conflicting results in MicroPython when compared to standard Python.
- Syntax
- Argument unpacking does not work if the argument being unpacked is the nth or greater argument where n is the number of bits in an MP_SMALL_INT.
- MicroPython allows using := to assign to the variable of a comprehension, CPython raises a SyntaxError.
- uPy requires spaces between literal numbers and keywords, CPy doesn’t
- Unicode name escapes are not implemented
- Core language
- f-strings don’t support concatenation with adjacent literals if the adjacent literals contain braces or are f-strings
- f-strings cannot support expressions that require parsing to resolve unbalanced nested braces and brackets
- Raw f-strings are not supported
- f-strings don’t support !a conversions
- Special method __del__ not implemented for user-defined classes
- Method Resolution Order (MRO) is not compliant with CPython
- When inheriting from multiple classes super() only calls one class
- Calling super() getter property in subclass will return a property object, not the value
- Error messages for methods may display unexpected argument counts
- Function objects do not have the
__module__
attribute - User-defined attributes for functions are not supported
- Context manager __exit__() not called in a generator which does not run to completion
- Local variables aren’t included in locals() result
- Code running in eval() function doesn’t have access to local variables
- __all__ is unsupported in __init__.py in MicroPython.
- __path__ attribute of a package has a different type (single string instead of list of strings) in MicroPython
- MicroPython doesn’t support namespace packages split across filesystem.
- Builtin types
- Modules