Skip to content
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

# General information about the project.
project = 'MicroPython'
copyright = '2014-2017, Damien P. George, Paul Sokolovsky, OpenMV LLC, and contributors'
copyright = '2014-2018, Damien P. George, Paul Sokolovsky, OpenMV LLC, and contributors'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
59 changes: 34 additions & 25 deletions docs/genrst/builtin_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Builtin Types
=============
Generated Tue 21 Nov 2017 21:31:50 UTC
Generated Sat 28 Apr 2018 19:34:04 UTC

Exception
---------
Expand Down Expand Up @@ -70,7 +70,7 @@ Exception in while loop condition may have unexpected line number
Sample code::

l = ["-foo", "-bar"]

i = 0
while l[i][0] == "-":
print("iter")
Expand All @@ -90,27 +90,35 @@ Sample code::

.. _cpydiff_types_exception_subclassinit:

Exception.__init__ raises TypeError if overridden and called by subclass
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Exception.__init__ method does not exist.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Cause:** Subclassing native classes is not fully supported in MicroPython.

**Workaround:** Call using ``super()`` instead::

class A(Exception):
def __init__(self):
super().__init__()

Sample code::

class A(Exception):
def __init__(self):
Exception.__init__(self)

a = A()

+-------------+-----------------------------------------------------------+
| CPy output: | uPy output: |
+-------------+-----------------------------------------------------------+
| | :: |
| | |
| | Traceback (most recent call last): |
| | File "<stdin>", line 11, in <module> |
| | File "<stdin>", line 9, in __init__ |
| | TypeError: argument should be a 'Exception' not a 'A' |
+-------------+-----------------------------------------------------------+
+-------------+-------------------------------------------------------------------------+
| CPy output: | uPy output: |
+-------------+-------------------------------------------------------------------------+
| | :: |
| | |
| | Traceback (most recent call last): |
| | File "<stdin>", line 15, in <module> |
| | File "<stdin>", line 13, in __init__ |
| | AttributeError: type object 'Exception' has no attribute '__init__' |
+-------------+-------------------------------------------------------------------------+

bytearray
---------
Expand Down Expand Up @@ -221,7 +229,7 @@ Sample code::

class A(int):
__add__ = lambda self, other: A(int(self) + other)

a = A(42)
print(a+a)

Expand Down Expand Up @@ -346,14 +354,15 @@ Sample code::
except UnicodeDecodeError:
print('UnicodeDecodeError')

+------------------------+-------------------------+
| CPy output: | uPy output: |
+------------------------+-------------------------+
| :: | :: |
| | |
| UnicodeDecodeError | '\u0840' |
| | Should not get here |
+------------------------+-------------------------+
+------------------------+---------------------------------------------------------+
| CPy output: | uPy output: |
+------------------------+---------------------------------------------------------+
| :: | :: |
| | |
| UnicodeDecodeError | Traceback (most recent call last): |
| | File "<stdin>", line 9, in <module> |
| | NameError: name 'UnicodeDecodeError' is not defined |
+------------------------+---------------------------------------------------------+

.. _cpydiff_types_str_endswith:

Expand Down Expand Up @@ -465,7 +474,7 @@ Sample code::

class S(str):
pass

s = S('hello')
print(s == 'hello')

Expand Down
69 changes: 61 additions & 8 deletions docs/genrst/core_language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Core Language
=============
Generated Tue 21 Nov 2017 21:31:50 UTC
Generated Sat 28 Apr 2018 19:34:04 UTC

Classes
-------
Expand Down Expand Up @@ -250,6 +250,59 @@ Sample code::
| Exit | |
+-------------+-------------+

Runtime
-------

.. _cpydiff_core_locals:

Local variables aren't included in locals() result
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Cause:** MicroPython doesn't maintain symbolic local environment, it is optimized to an array of slots. Thus, local variables can't be accessed by a name.

Sample code::

def test():
val = 2
print(locals())

test()

+----------------+------------------------------------------------------------------------------------------------+
| CPy output: | uPy output: |
+----------------+------------------------------------------------------------------------------------------------+
| :: | :: |
| | |
| {'val': 2} | {'test': <function test at 0x7f014da2e560>, '__name__': '__main__', '__file__': '<stdin>'} |
+----------------+------------------------------------------------------------------------------------------------+

.. _cpydiff_core_locals_eval:

Code running in eval() function doesn't have access to local variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Cause:** MicroPython doesn't maintain symbolic local environment, it is optimized to an array of slots. Thus, local variables can't be accessed by a name. Effectively, ``eval(expr)`` in MicroPython is equivalent to ``eval(expr, globals(), globals())``.

Sample code::

val = 1

def test():
val = 2
print(val)
eval("print(val)")

test()

+-------------+-------------+
| CPy output: | uPy output: |
+-------------+-------------+
| :: | :: |
| | |
| 2 | 2 |
| 2 | 1 |
+-------------+-------------+

import
------

Expand All @@ -268,13 +321,13 @@ Sample code::

print(modules.__path__)

+-----------------------------------------------------------------------------+-------------------------------+
| CPy output: | uPy output: |
+-----------------------------------------------------------------------------+-------------------------------+
| :: | :: |
| | |
| ['/home/kwagyeman/GitHub/openmv-doc/micropython/tests/cpydiff/modules'] | ../tests/cpydiff//modules |
+-----------------------------------------------------------------------------+-------------------------------+
+---------------------------------------------------------------------------------------+-------------------------------+
| CPy output: | uPy output: |
+---------------------------------------------------------------------------------------+-------------------------------+
| :: | :: |
| | |
| ['/home/kwagyeman/Documents/GitHub/openmv/src/micropython/tests/cpydiff/modules'] | ../tests/cpydiff//modules |
+---------------------------------------------------------------------------------------+-------------------------------+

.. _cpydiff_core_import_prereg:

Expand Down
51 changes: 41 additions & 10 deletions docs/genrst/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Modules
=======
Generated Tue 21 Nov 2017 21:31:50 UTC
Generated Sat 28 Apr 2018 19:34:04 UTC

array
-----
Expand Down Expand Up @@ -70,6 +70,37 @@ Sample code::
| | NotImplementedError: only slices with step=1 (aka None) are supported |
+----------------+---------------------------------------------------------------------------+

builtins
--------

.. _cpydiff_builtin_next_arg2:

Second argument to next() is not implemented
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Cause:** MicroPython is optimised for code space.

**Workaround:** Instead of ``val = next(it, deflt)`` use::

try:
val = next(it)
except StopIteration:
val = deflt

Sample code::

print(next(iter(range(0)), 42))

+-------------+-----------------------------------------------------------------------+
| CPy output: | uPy output: |
+-------------+-----------------------------------------------------------------------+
| :: | :: |
| | |
| 42 | Traceback (most recent call last): |
| | File "<stdin>", line 12, in <module> |
| | TypeError: function takes 1 positional arguments but 2 were given |
+-------------+-----------------------------------------------------------------------+

deque
-----

Expand All @@ -86,15 +117,15 @@ Sample code::
D = collections.deque()
print(D)

+---------------+--------------------------------------------------------------+
| CPy output: | uPy output: |
+---------------+--------------------------------------------------------------+
| :: | :: |
| | |
| deque([]) | Traceback (most recent call last): |
| | File "<stdin>", line 8, in <module> |
| | AttributeError: 'module' object has no attribute 'deque' |
+---------------+--------------------------------------------------------------+
+---------------+-----------------------------------------------------------------+
| CPy output: | uPy output: |
+---------------+-----------------------------------------------------------------+
| :: | :: |
| | |
| deque([]) | Traceback (most recent call last): |
| | File "<stdin>", line 8, in <module> |
| | TypeError: function missing 2 required positional arguments |
+---------------+-----------------------------------------------------------------+

json
----
Expand Down
2 changes: 1 addition & 1 deletion docs/genrst/syntax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Syntax
======
Generated Tue 21 Nov 2017 21:31:50 UTC
Generated Sat 28 Apr 2018 19:34:04 UTC

Spaces
------
Expand Down
4 changes: 2 additions & 2 deletions docs/library/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ it will fallback to loading the built-in ``ujson`` module.
math.rst
sys.rst
ubinascii.rst
ucollections.rst
uerrno.rst
uhashlib.rst
uheapq.rst
Expand All @@ -187,6 +186,7 @@ it will fallback to loading the built-in ``ujson`` module.
ustruct.rst
utime.rst
uzlib.rst
_thread.rst


MicroPython-specific libraries
Expand Down Expand Up @@ -274,4 +274,4 @@ the following libraries.
omv.mjpeg.rst
omv.lcd.rst
omv.fir.rst
omv.cpufreq.rst
omv.omv.rst
Loading