From 2ff7148d092547e9573c9136e44a38bc4593e133 Mon Sep 17 00:00:00 2001 From: bildzeitung Date: Mon, 14 May 2018 14:31:56 -0400 Subject: Update docs s/ucollections/collections/g --- docs/library/collections.rst | 57 +++++++++++++++++++++++++++++++++++++++++++ docs/library/index.rst | 2 +- docs/library/ucollections.rst | 57 ------------------------------------------- 3 files changed, 58 insertions(+), 58 deletions(-) create mode 100644 docs/library/collections.rst delete mode 100644 docs/library/ucollections.rst diff --git a/docs/library/collections.rst b/docs/library/collections.rst new file mode 100644 index 000000000..849e8b694 --- /dev/null +++ b/docs/library/collections.rst @@ -0,0 +1,57 @@ +:mod:`collections` -- collection and container types +===================================================== + +.. include:: ../templates/unsupported_in_circuitpython.inc + +.. module:: collections + :synopsis: collection and container types + +|see_cpython_module| :mod:`cpython:collections`. + +This module implements advanced collection and container types to +hold/accumulate various objects. + +Classes +------- + +.. function:: namedtuple(name, fields) + + This is factory function to create a new namedtuple type with a specific + name and set of fields. A namedtuple is a subclass of tuple which allows + to access its fields not just by numeric index, but also with an attribute + access syntax using symbolic field names. Fields is a sequence of strings + specifying field names. For compatibility with CPython it can also be a + a string with space-separated field named (but this is less efficient). + Example of use:: + + from collections import namedtuple + + MyTuple = namedtuple("MyTuple", ("id", "name")) + t1 = MyTuple(1, "foo") + t2 = MyTuple(2, "bar") + print(t1.name) + assert t2.name == t2[1] + +.. function:: OrderedDict(...) + + ``dict`` type subclass which remembers and preserves the order of keys + added. When ordered dict is iterated over, keys/items are returned in + the order they were added:: + + from collections import OrderedDict + + # To make benefit of ordered keys, OrderedDict should be initialized + # from sequence of (key, value) pairs. + d = OrderedDict([("z", 1), ("a", 2)]) + # More items can be added as usual + d["w"] = 5 + d["b"] = 3 + for k, v in d.items(): + print(k, v) + + Output:: + + z 1 + a 2 + w 5 + b 3 diff --git a/docs/library/index.rst b/docs/library/index.rst index 466068640..c7b6879aa 100644 --- a/docs/library/index.rst +++ b/docs/library/index.rst @@ -21,7 +21,7 @@ Python standard libraries and micro-libraries gc.rst sys.rst binascii.rst - ucollections.rst + collections.rst uerrno.rst hashlib.rst uheapq.rst diff --git a/docs/library/ucollections.rst b/docs/library/ucollections.rst deleted file mode 100644 index 396ba3c87..000000000 --- a/docs/library/ucollections.rst +++ /dev/null @@ -1,57 +0,0 @@ -:mod:`ucollections` -- collection and container types -===================================================== - -.. include:: ../templates/unsupported_in_circuitpython.inc - -.. module:: ucollections - :synopsis: collection and container types - -|see_cpython_module| :mod:`cpython:collections`. - -This module implements advanced collection and container types to -hold/accumulate various objects. - -Classes -------- - -.. function:: namedtuple(name, fields) - - This is factory function to create a new namedtuple type with a specific - name and set of fields. A namedtuple is a subclass of tuple which allows - to access its fields not just by numeric index, but also with an attribute - access syntax using symbolic field names. Fields is a sequence of strings - specifying field names. For compatibility with CPython it can also be a - a string with space-separated field named (but this is less efficient). - Example of use:: - - from ucollections import namedtuple - - MyTuple = namedtuple("MyTuple", ("id", "name")) - t1 = MyTuple(1, "foo") - t2 = MyTuple(2, "bar") - print(t1.name) - assert t2.name == t2[1] - -.. function:: OrderedDict(...) - - ``dict`` type subclass which remembers and preserves the order of keys - added. When ordered dict is iterated over, keys/items are returned in - the order they were added:: - - from ucollections import OrderedDict - - # To make benefit of ordered keys, OrderedDict should be initialized - # from sequence of (key, value) pairs. - d = OrderedDict([("z", 1), ("a", 2)]) - # More items can be added as usual - d["w"] = 5 - d["b"] = 3 - for k, v in d.items(): - print(k, v) - - Output:: - - z 1 - a 2 - w 5 - b 3 -- cgit v1.2.3 From a8cc4a1a621a476bb761f08a484fc7882664b4f9 Mon Sep 17 00:00:00 2001 From: bildzeitung Date: Mon, 14 May 2018 14:33:50 -0400 Subject: Updated library source: ucollections -> collections --- py/modcollections.c | 2 +- py/objmodule.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/py/modcollections.c b/py/modcollections.c index 1a1560387..837ec2f92 100644 --- a/py/modcollections.c +++ b/py/modcollections.c @@ -29,7 +29,7 @@ #if MICROPY_PY_COLLECTIONS STATIC const mp_rom_map_elem_t mp_module_collections_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ucollections) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_collections) }, { MP_ROM_QSTR(MP_QSTR_namedtuple), MP_ROM_PTR(&mp_namedtuple_obj) }, #if MICROPY_PY_COLLECTIONS_ORDEREDDICT { MP_ROM_QSTR(MP_QSTR_OrderedDict), MP_ROM_PTR(&mp_type_ordereddict) }, diff --git a/py/objmodule.c b/py/objmodule.c index 3bea19644..e3464ecfa 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -151,7 +151,7 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { { MP_ROM_QSTR(MP_QSTR_uio), MP_ROM_PTR(&mp_module_io) }, #endif #if MICROPY_PY_COLLECTIONS - { MP_ROM_QSTR(MP_QSTR_ucollections), MP_ROM_PTR(&mp_module_collections) }, + { MP_ROM_QSTR(MP_QSTR_collections), MP_ROM_PTR(&mp_module_collections) }, #endif #if MICROPY_PY_STRUCT { MP_ROM_QSTR(MP_QSTR_ustruct), MP_ROM_PTR(&mp_module_ustruct) }, -- cgit v1.2.3 From bf26ffbf568b48bdd9bf914d5b1b6c91954c4aa1 Mon Sep 17 00:00:00 2001 From: bildzeitung Date: Mon, 14 May 2018 14:43:34 -0400 Subject: Updated tests; removed try/catch for ucollections --- tests/basics/class_store_class.py | 7 ++----- tests/basics/namedtuple1.py | 5 +---- tests/basics/namedtuple1_cpython_compat.py | 5 +---- tests/basics/ordereddict1.py | 7 ++----- tests/basics/ordereddict_eq.py | 7 ++----- tests/bench/var-8-namedtuple-1st.py | 2 +- tests/bench/var-8.1-namedtuple-5th.py | 2 +- tests/skip_if.py | 5 +---- 8 files changed, 11 insertions(+), 29 deletions(-) diff --git a/tests/basics/class_store_class.py b/tests/basics/class_store_class.py index 8f3e542d1..504f460a7 100644 --- a/tests/basics/class_store_class.py +++ b/tests/basics/class_store_class.py @@ -5,11 +5,8 @@ try: from collections import namedtuple except ImportError: - try: - from ucollections import namedtuple - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit import skip_if skip_if.no_cpython_compat() diff --git a/tests/basics/namedtuple1.py b/tests/basics/namedtuple1.py index 1b176b232..63d9eddd4 100644 --- a/tests/basics/namedtuple1.py +++ b/tests/basics/namedtuple1.py @@ -1,8 +1,5 @@ try: - try: - from collections import namedtuple - except ImportError: - from ucollections import namedtuple + from collections import namedtuple except ImportError: print("SKIP") raise SystemExit diff --git a/tests/basics/namedtuple1_cpython_compat.py b/tests/basics/namedtuple1_cpython_compat.py index a1b852d90..061ae94e5 100644 --- a/tests/basics/namedtuple1_cpython_compat.py +++ b/tests/basics/namedtuple1_cpython_compat.py @@ -2,10 +2,7 @@ import skip_if skip_if.no_cpython_compat() try: - try: - from collections import namedtuple - except ImportError: - from ucollections import namedtuple + from collections import namedtuple except ImportError: skip_if.skip() diff --git a/tests/basics/ordereddict1.py b/tests/basics/ordereddict1.py index d1633f0bb..9c62b2d62 100644 --- a/tests/basics/ordereddict1.py +++ b/tests/basics/ordereddict1.py @@ -1,11 +1,8 @@ try: from collections import OrderedDict except ImportError: - try: - from ucollections import OrderedDict - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit d = OrderedDict([(10, 20), ("b", 100), (1, 2)]) print(len(d)) diff --git a/tests/basics/ordereddict_eq.py b/tests/basics/ordereddict_eq.py index c69daf880..e103c867e 100644 --- a/tests/basics/ordereddict_eq.py +++ b/tests/basics/ordereddict_eq.py @@ -1,11 +1,8 @@ try: from collections import OrderedDict except ImportError: - try: - from ucollections import OrderedDict - except ImportError: - print("SKIP") - raise SystemExit + print("SKIP") + raise SystemExit x = OrderedDict() y = OrderedDict() diff --git a/tests/bench/var-8-namedtuple-1st.py b/tests/bench/var-8-namedtuple-1st.py index d862480a5..90ae7209d 100644 --- a/tests/bench/var-8-namedtuple-1st.py +++ b/tests/bench/var-8-namedtuple-1st.py @@ -1,5 +1,5 @@ import bench -from ucollections import namedtuple +from collections import namedtuple T = namedtuple("Tup", ["num", "bar"]) diff --git a/tests/bench/var-8.1-namedtuple-5th.py b/tests/bench/var-8.1-namedtuple-5th.py index 0bcf66180..0d5789d2e 100644 --- a/tests/bench/var-8.1-namedtuple-5th.py +++ b/tests/bench/var-8.1-namedtuple-5th.py @@ -1,5 +1,5 @@ import bench -from ucollections import namedtuple +from collections import namedtuple T = namedtuple("Tup", ["foo1", "foo2", "foo3", "foo4", "num"]) diff --git a/tests/skip_if.py b/tests/skip_if.py index 8d0ed8f21..7d6c5b207 100644 --- a/tests/skip_if.py +++ b/tests/skip_if.py @@ -68,10 +68,7 @@ def board_not_in(*board): def no_cpython_compat(): try: - try: - from collections import namedtuple - except ImportError: - from ucollections import namedtuple + from collections import namedtuple except ImportError: skip() try: -- cgit v1.2.3