{ "info": { "author": "Eric V. Smith", "author_email": "eric@trueblade.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "===========\nnamedlist\n===========\n\nOverview\n========\n\nnamedlist provides 2 factory functions, namedlist.namedlist and\nnamedlist.namedtuple. namedlist.namedtuple is similar to\ncollections.namedtuple, with the following differences:\n\n* namedlist.namedtuple supports per-field default values.\n\n* namedlist.namedtuple supports an optional default value, to be used\n by all fields that do not have an explicit default value.\n\n\nnamedlist.namedlist is similar, with this additional difference:\n\n* namedlist.namedlist instances are mutable.\n\nTypical usage\n=============\n\nYou can use namedlist like a mutable namedtuple::\n\n >>> from namedlist import namedlist\n\n >>> Point = namedlist('Point', 'x y')\n >>> p = Point(1, 3)\n >>> p.x = 2\n >>> assert p.x == 2\n >>> assert p.y == 3\n\nOr, you can specify a default value for all fields::\n\n >>> Point = namedlist('Point', 'x y', default=3)\n >>> p = Point(y=2)\n >>> assert p.x == 3\n >>> assert p.y == 2\n\nOr, you can specify per-field default values::\n\n >>> Point = namedlist('Point', [('x', 0), ('y', 100)])\n >>> p = Point()\n >>> assert p.x == 0\n >>> assert p.y == 100\n\nYou can also specify the per-field defaults with a mapping, instead\nof an iterable. Note that this is only useful with an ordered\nmapping, such as an OrderedDict::\n\n >>> from collections import OrderedDict\n >>> Point = namedlist('Point', OrderedDict((('y', 0),\n ... ('x', 100))))\n >>> p = Point()\n >>> p\n Point(y=0, x=100)\n\nThe default value will only be used if it is provided and a per-field\ndefault is not used::\n\n >>> Point = namedlist('Point', ['x', ('y', 100)], default=10)\n >>> p = Point()\n >>> assert p.x == 10\n >>> assert p.y == 100\n\nIf you use a mapping, the value NO_DEFAULT is convenient to specify\nthat a field uses the default value::\n\n >>> from namedlist import NO_DEFAULT\n >>> Point = namedlist('Point', OrderedDict((('y', NO_DEFAULT),\n ... ('x', 100))),\n ... default=5)\n >>> p = Point()\n >>> assert p.x == 100\n >>> assert p.y == 5\n\nnamedtuple is similar, except the instances are immutable::\n\n >>> from namedlist import namedtuple\n >>> Point = namedtuple('Point', 'x y', default=3)\n >>> p = Point(y=2)\n >>> assert p.x == 3\n >>> assert p.y == 2\n >>> p.x = 10\n Traceback (most recent call last):\n ...\n AttributeError: can't set attribute\n\nAll of the documentation below in the Specifying Fields and Specifying\nDefaults sections applies to namedlist.namedlist and\nnamedlist.namedtuple.\n\nCreating types\n==============\n\nSpecifying Fields\n-----------------\n\nFields in namedlist.namedlist or namedlist.namedtuple can be specified\nas in collections.namedtuple: as either a string specifing the field\nnames, or as a iterable of field names. These two uses are\nequivalent::\n\n >>> Point = namedlist('Point', 'x y')\n >>> Point = namedlist('Point', ['x', 'y'])\n\nAs are these::\n\n >>> Point = namedtuple('Point', 'x y')\n >>> Point = namedtuple('Point', ['x', 'y'])\n\nIf using a string, commas are first converted to spaces. So these are\nequivalent::\n\n >>> Point = namedlist('Point', 'x y')\n >>> Point = namedlist('Point', 'x,y')\n\n\nSpecifying Defaults\n-------------------\n\nPer-field defaults can be specified by supplying a 2-tuple (name,\ndefault_value) instead of just a string for the field name. This is\nonly supported when you specify a list of field names::\n\n >>> Point = namedlist('Point', [('x', 0), ('y', 0)])\n >>> p = Point(3)\n >>> assert p.x == 3\n >>> assert p.y == 0\n\nOr, using namedtuple::\n\n >>> Point = namedtuple('Point', [('x', 0), ('y', 0)])\n >>> p = Point(3)\n >>> assert p.x == 3\n >>> assert p.y == 0\n\n\nIn addition to, or instead of, these per-field defaults, you can also\nspecify a default value which is used when no per-field default value\nis specified::\n\n >>> Point = namedlist('Point', 'x y z', default=0)\n >>> p = Point(y=3)\n >>> assert p.x == 0\n >>> assert p.y == 3\n >>> assert p.z == 0\n\n >>> Point = namedlist('Point', [('x', 0), 'y', ('z', 0)], default=4)\n >>> p = Point(z=2)\n >>> assert p.x == 0\n >>> assert p.y == 4\n >>> assert p.z == 2\n\nIn addition to supplying the field names as an iterable of 2-tuples,\nyou can also specify a mapping. The keys will be the field names, and\nthe values will be the per-field default values. This is most useful\nwith an OrderedDict, as the order of the fields will then be\ndeterministic. The module variable NO_DEFAULT can be specified if you\nwant a field to use the per-type default value instead of specifying\nit with a field::\n\n >>> Point = namedlist('Point', OrderedDict((('x', 0),\n ... ('y', NO_DEFAULT),\n ... ('z', 0),\n ... )),\n ... default=4)\n >>> p = Point(z=2)\n >>> assert p.x == 0\n >>> assert p.y == 4\n >>> assert p.z == 2\n\nWriting to values\n-----------------\n\nInstances of the classes generated by namedlist.namedlist are fully\nwritable, unlike the tuple-derived classes returned by\ncollections.namedtuple or namedlist.namedtuple::\n\n >>> Point = namedlist('Point', 'x y')\n >>> p = Point(1, 2)\n >>> p.y = 4\n >>> assert p.x == 1\n >>> assert p.y == 4\n\n\nSpecifying __slots__\n--------------------\n\nFor namedlist.namedlist, by default, the returned class sets __slots__\nwhich is initialized to the field names. While this decreases memory\nusage by eliminating the instance dict, it also means that you cannot\ncreate new instance members.\n\nTo change this behavior, specify use_slots=False when creating the\nnamedlist::\n\n >>> Point = namedlist('Point', 'x y', use_slots=False)\n >>> p = Point(0, 1)\n >>> p.z = 2\n >>> assert p.x == 0\n >>> assert p.y == 1\n >>> assert p.z == 2\n\nHowever, note that this method does not add the new variable to\n_fields, so it is not recognized when iterating over the instance::\n\n >>> list(p)\n [0, 1]\n >>> sorted(p._asdict().items())\n [('x', 0), ('y', 1)]\n\n\nAdditional class members\n------------------------\n\nnamedlist.namedlist and namedlist.namedtuple classes contain these members:\n\n* _asdict(): Returns a dict which maps field names to their\n corresponding values.\n\n* _fields: Tuple of strings listing the field names. Useful for introspection.\n\n\nRenaming invalid field names\n----------------------------\n\nThis functionality is identical to collections.namedtuple. If you\nspecify rename=True, then any invalid field names are changed to _0,\n_1, etc. Reasons for a field name to be invalid are:\n\n* Zero length strings.\n\n* Containing characters other than alphanumerics and underscores.\n\n* A conflict with a Python reserved identifier.\n\n* Beginning with a digit.\n\n* Beginning with an underscore.\n\n* Using the same field name more than once.\n\nFor example::\n\n >>> Point = namedlist('Point', 'x x for', rename=True)\n >>> assert Point._fields == ('x', '_1', '_2')\n\n\nMutable default values\n----------------------\n\nFor namedlist.namelist, be aware of specifying mutable default\nvalues. Due to the way Python handles default values, each instance of\na namedlist will share the default. This is especially problematic\nwith default values that are lists. For example::\n\n >>> A = namedlist('A', [('x', [])])\n >>> a = A()\n >>> a.x.append(4)\n >>> b = A()\n >>> assert b.x == [4]\n\nThis is probably not the desired behavior, so see the next section.\n\n\nSpecifying a factory function for default values\n------------------------------------------------\n\nFor namedlist.namedlist, you can supply a zero-argument callable for a\ndefault, by wrapping it in a FACTORY call. The only change in this\nexample is to change the default from `[]` to `FACTORY(list)`. But\nnote that `b.x` is a new list object, not shared with `a.x`::\n\n >>> from namedlist import FACTORY\n >>> A = namedlist('A', [('x', FACTORY(list))])\n >>> a = A()\n >>> a.x.append(4)\n >>> b = A()\n >>> assert b.x == []\n\nEvery time a new instance is created, your callable (in this case,\n`list`), will be called to produce a new instance for the default\nvalue.\n\nIterating over instances\n------------------------\n\nBecause instances are iterable (like lists or tuples), iteration works\nthe same way. Values are returned in definition order::\n\n >>> Point = namedlist('Point', 'x y z t')\n >>> p = Point(1.0, 42.0, 3.14, 2.71828)\n >>> for value in p:\n ... print(value)\n 1.0\n 42.0\n 3.14\n 2.71828\n\n\nnamedlist specific functions\n============================\n\n_update\n-------\n\n`namedlist._update()` is similar to `dict.update()`. It is used to\nmutate a namedlist.namedlist instance with new values::\n\n >>> Point = namedlist('Point', 'x y z')\n >>> p = Point(1, 2, 3)\n >>> p.z = 4\n >>> p._update(y=5, x=6)\n >>> p\n Point(x=6, y=5, z=4)\n\n >>> p._update({'x': 7, 'z': 8})\n >>> p\n Point(x=7, y=5, z=8)\n\n >>> p._update([('z', 9), ('y', 10)])\n >>> p\n Point(x=7, y=10, z=9)\n\n\nCreating and using instances\n============================\n\nBecause the type returned by namedlist or namedtuple is a normal\nPython class, you create instances as you would with any Python class.\n\n\nChange log\n==========\n\n1.7 2015-05-15 Eric V. Smith\n----------------------------\n\n* Changed RPM name to python3-namedlist if running with python 3.\n\n* No code changes.\n\n1.6 2014-12-23 Eric V. Smith\n----------------------------\n\n* Add namedlist._update(), similar to dict.update(). Thanks to Arthur\n Skowronek (issue #23).\n\n* Add namedlist._replace(), similar to namedtuple._replace (issue\n #24).\n\n1.5 2014-05-20 Eric V. Smith\n----------------------------\n\n* Support slices in namedlist.__getattr__ (issue #22).\n\n1.4 2014-03-14 Eric V. Smith\n----------------------------\n\n* Add MANIFEST.in to MANIFEST.in, so it will be included in sdists\n (issue #21).\n\n1.3 2014-03-12 Eric V. Smith\n----------------------------\n\n* Support unicode type and field names in Python 2.x (issue #19). The\n identifiers still must be ASCII only, but you can pass them as\n unicode. This is useful for code that needs to run under both Python\n 2 and Python 3.\n\n1.2 2014-02-13 Eric V. Smith\n----------------------------\n\n* Produce an RPM named python-namedlist (issue #17).\n\n* Add namedtuple (issue #10). Passes all of the collections.namedtuple\n tests, except those related to _source. Those tests don't apply\n given our different approach to dynamic class creation. All other\n collections.namedtuple tests have been copied to our test suite.\n\n1.1 2014-02-07 Eric V. Smith\n----------------------------\n\n* Added __dict__ so vars() will be supported.\n\n* Fixed pickling from another module (issue #14).\n\n* Moved tests to a separate file (issue #15).\n\n1.0 2014-02-04 Eric V. Smith\n----------------------------\n\n* Declare the API stable and release version 1.0.\n\n* Support python 2.6 (issue #8). The doctests don't pass because\n OrderedDict isn't available until 2.7.\n\n0.4 2014-02-04 Eric V. Smith\n----------------------------\n\n* Add docstring (issue #7).\n\n* Fixed README.txt typos (thanks pombredanne on bitbucket).\n\n0.3 2014-01-29 Eric V. Smith\n----------------------------\n\n* Removed documentation left over from recordtype.\n\n* Make instances unhashable (issue #2).\n\n* For python3, use str.isidentifier (issue #1).\n\n* Reorganize code for name checking. No functional changes.\n\n* Make instances iterable (issue #3).\n\n* Add collections.Sequence ABC (issue #4).\n\n* Have \"python setup.py test\" also run doctests (issue #5).\n\n0.2 2014-01-28 Eric V. Smith\n----------------------------\n\n* Added MANIFEST.in.\n\n* Hopefully fixed a problem with .rst formatting in CHANGES.txt.\n\n0.1 2014-01-28 Eric V. Smith\n----------------------------\n\n* Initial release.\n\n* Based off my recordtype project, but uses ast generation instead of\n building up a string and exec-ing it. This has a number of advantages:\n\n - Supporting both python2 and python3 is easier. exec has the\n anti-feature of having different syntax in the two languages.\n\n - Adding additional features is easier, because I can write in real\n Python instead of having to write the string version, and deal\n with all of the escaping and syntax errors.\n\n* Added FACTORY, to allow namedlist to work even with mutable defaults.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/ericvsmith/namedlist", "keywords": null, "license": "Apache License Version 2.0", "maintainer": null, "maintainer_email": null, "name": "namedlist", "package_url": "https://pypi.org/project/namedlist/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/namedlist/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://bitbucket.org/ericvsmith/namedlist" }, "release_url": "https://pypi.org/project/namedlist/1.7/", "requires_dist": null, "requires_python": null, "summary": "Similar to namedtuple, but instances are mutable.", "version": "1.7" }, "last_serial": 1549736, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "d3a49a5e5cb62b736c1ac5e1c738afbb", "sha256": "5de40a60f93da66a7f8583db280c14c23d5936635ef961840725c029b5efc0bd" }, "downloads": -1, "filename": "namedlist-0.1.tar.gz", "has_sig": false, "md5_digest": "d3a49a5e5cb62b736c1ac5e1c738afbb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9200, "upload_time": "2014-01-28T14:14:47", "url": "https://files.pythonhosted.org/packages/7d/09/7c1fc5d2de1cb60bcf2aa81d490fd3fe2f755e1831fba62c2ee807ca5dd4/namedlist-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "2b00310f5dcd541f5dd811d4156655eb", "sha256": "0b5bcfb49691f9cad720a025164ca005ec18e4b7bb003f80eac356a128c4a5c6" }, "downloads": -1, "filename": "namedlist-0.2.tar.gz", "has_sig": false, "md5_digest": "2b00310f5dcd541f5dd811d4156655eb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13217, "upload_time": "2014-01-28T18:37:48", "url": "https://files.pythonhosted.org/packages/77/8f/321020d9878230af5966020900b6b9f0d373122a57930e6b3e4fe162c67d/namedlist-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "5f4c6c094da5262ef8c84c437c074996", "sha256": "ebf6101dea420b60d703f752aa40e54fff9e0f73a372048daad677ca61671e17" }, "downloads": -1, "filename": "namedlist-0.3.tar.gz", "has_sig": false, "md5_digest": "5f4c6c094da5262ef8c84c437c074996", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14413, "upload_time": "2014-01-30T02:00:38", "url": "https://files.pythonhosted.org/packages/e6/9f/933e3a8abaf3cee6c41fdf9672c91e407d6b0df927bbf1ea7fd3dff1e2e8/namedlist-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "2429b3fa68f0179fd6187b5c04e42ad7", "sha256": "3aef302f51ab98623c39036bdadaa66c5c841ccf61aff5a051753f77bc0883ec" }, "downloads": -1, "filename": "namedlist-0.4.tar.gz", "has_sig": false, "md5_digest": "2429b3fa68f0179fd6187b5c04e42ad7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15152, "upload_time": "2014-02-04T15:31:54", "url": "https://files.pythonhosted.org/packages/b9/82/17afef68afa3cb4f1b0d78e054cb0f4f5493ad9155c06d0dcab298b1c9f5/namedlist-0.4.tar.gz" } ], "1.0": [ { "comment_text": "", "digests": { "md5": "1f383937444283a3a2e71f918570c976", "sha256": "511eefa4ef8eb3863aee04eb430b6b08883aa4e578a45fb47b6a7e02abd98f85" }, "downloads": -1, "filename": "namedlist-1.0.tar.gz", "has_sig": false, "md5_digest": "1f383937444283a3a2e71f918570c976", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15503, "upload_time": "2014-02-04T18:30:22", "url": "https://files.pythonhosted.org/packages/68/4b/b9e5d5f70da872c5095d62e39136878c9a3da01c15572fd6189e18ca0984/namedlist-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "4c00d972250a97e3549411fe6a02380a", "sha256": "1cebb94b188992b8feb5d83045c062a8838b8b52daa054dd2f3b13f01be8e85c" }, "downloads": -1, "filename": "namedlist-1.1.tar.gz", "has_sig": false, "md5_digest": "4c00d972250a97e3549411fe6a02380a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15872, "upload_time": "2014-02-07T14:40:44", "url": "https://files.pythonhosted.org/packages/6c/92/29c0b35e12df7585ef793096c2005e50228b491c6d63e57cdfb80d0d4797/namedlist-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "2bf3dca18a5a4afda1427d0f4c52a1b5", "sha256": "b08c23482d1190ae01915b1b349bb2e7890cdc8c44be91778a975bc9da5752f3" }, "downloads": -1, "filename": "namedlist-1.2.tar.gz", "has_sig": false, "md5_digest": "2bf3dca18a5a4afda1427d0f4c52a1b5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19716, "upload_time": "2014-02-13T14:14:29", "url": "https://files.pythonhosted.org/packages/5b/5c/ed47b82b46e7d0d646719236e39dd1c96ef3827f32311119b2ab86432db1/namedlist-1.2.tar.gz" } ], "1.3": [ { "comment_text": "", "digests": { "md5": "46ff28e6aef269741cbb813b1726ab86", "sha256": "0c4583fdc14b6fee1435b4a4c211349613bde6c8a6235560eddd395c75f0a33e" }, "downloads": -1, "filename": "namedlist-1.3.tar.gz", "has_sig": false, "md5_digest": "46ff28e6aef269741cbb813b1726ab86", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19852, "upload_time": "2014-03-12T21:11:46", "url": "https://files.pythonhosted.org/packages/70/07/1f9c5a0c74b9fde0e73efa918d2720394e8b15756e443d43b16babbeaa60/namedlist-1.3.tar.gz" } ], "1.4": [ { "comment_text": "", "digests": { "md5": "09eb613c625e73c64a1f84427e1b7170", "sha256": "d361816745b106347203bac3442021ef33c7b1334268417f23316732ccd57b15" }, "downloads": -1, "filename": "namedlist-1.4.tar.gz", "has_sig": false, "md5_digest": "09eb613c625e73c64a1f84427e1b7170", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19968, "upload_time": "2014-03-15T02:36:51", "url": "https://files.pythonhosted.org/packages/d8/13/df28c11c6ae6042698ec20b65b63e05744f1047c9abfafe5aef568f378bf/namedlist-1.4.tar.gz" } ], "1.5": [ { "comment_text": "", "digests": { "md5": "a19f74e5deaac3dc8bdd99743450b692", "sha256": "184fc4ce6cd749f0dc1e744a25c3da8eef0fd80e4c0ab3386dc6e8abae305755" }, "downloads": -1, "filename": "namedlist-1.5.tar.gz", "has_sig": false, "md5_digest": "a19f74e5deaac3dc8bdd99743450b692", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20155, "upload_time": "2014-05-20T12:16:31", "url": "https://files.pythonhosted.org/packages/4e/4b/468dede22d4dce53c458e693ff6fe21da4dc30807e9a7f65a65fdeca236c/namedlist-1.5.tar.gz" } ], "1.6": [ { "comment_text": "", "digests": { "md5": "91c45089db1e218d8ff225510bdcbbb1", "sha256": "d5678105ed76289f542cc5eed0ed901b60ea477486ae68bc8906c2f93db5bfc7" }, "downloads": -1, "filename": "namedlist-1.6.tar.gz", "has_sig": false, "md5_digest": "91c45089db1e218d8ff225510bdcbbb1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21334, "upload_time": "2014-12-23T11:16:55", "url": "https://files.pythonhosted.org/packages/20/b2/72224a4832ea004341ace7bf301e9c27110df0ac642194ffeff7ba8f0554/namedlist-1.6.tar.gz" } ], "1.7": [ { "comment_text": "", "digests": { "md5": "91932e6797b13df64bffcec4b5c810a3", "sha256": "190b39ceaf1d6b59999811259e61beb1b26aaa482fb8c95538294d551461c986" }, "downloads": -1, "filename": "namedlist-1.7.tar.gz", "has_sig": false, "md5_digest": "91932e6797b13df64bffcec4b5c810a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21447, "upload_time": "2015-05-16T17:32:14", "url": "https://files.pythonhosted.org/packages/88/49/f7db251a949311c4f09f583e1b3c5a7e377220d5913607e6ab453446fe7e/namedlist-1.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "91932e6797b13df64bffcec4b5c810a3", "sha256": "190b39ceaf1d6b59999811259e61beb1b26aaa482fb8c95538294d551461c986" }, "downloads": -1, "filename": "namedlist-1.7.tar.gz", "has_sig": false, "md5_digest": "91932e6797b13df64bffcec4b5c810a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21447, "upload_time": "2015-05-16T17:32:14", "url": "https://files.pythonhosted.org/packages/88/49/f7db251a949311c4f09f583e1b3c5a7e377220d5913607e6ab453446fe7e/namedlist-1.7.tar.gz" } ] }