{ "info": { "author": "Quantopian Inc.", "author_email": "opensource@quantopian.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Utilities" ], "description": "metautils\n=========\n\nUtilities for writing and composing metaclasses.\n\nTemplate Model\n-----------------------\n\nWhy do we need or want to write class templates.\n\nConsider the two metaclasses.\n\n.. code:: python\n\n class AllLower(type):\n def __new__(mcls, name, bases, dict_):\n dict_ = {k.lower(): v for k, v in dict_.items()}\n return super().__new__(mcls, name, bases, dict_)\n\n\n class MethodCatcher(type):\n def __new__(mcls, name, bases, dict_):\n dict_['methods'] = [v for v in dict_.values() if callable(v)]\n return super().__new__(mcls, name, bases, dict_)\n\nWhat would we do if we wanted to make a class that used *BOTH* of these\nmetaclasses? Using a class that subclasses both ``AllLower`` and\n``MethodCatcher`` does not work, what we want is a way to chain them.\n\nWith the class template model, we could have written our metaclasses\nas:\n\n.. code:: python\n\n from metautils import T, templated\n\n class AllLower(T):\n @templated\n def __new__(mcls, name, bases, dict_, T_):\n dict_ = {k.lower(): v for k, v in dict_.items()}\n return T_.__new__(mcls, name, bases, dict_)\n\n\n class MethodCatcher(T):\n @templated\n def __new__(mcls, name, bases, dict_, T_):\n dict_['methods'] = [v for v in dict_.values() if callable(v)];\n return T_.__new__(mcls, name, bases, dict_)\n\nNow we can define classes that use *BOTH* of these metaclasses like so:\n\n.. code:: python\n\n class C(object, metaclass=MethodCatcher(AllLower())):\n def F():\n pass\n\n def g():\n pass\n\n a = 'a'\n B = 'b'\n\nWe can see that this applied the composition of the metaclasses.\n\n.. code:: python\n\n >>> C.f\n \n >>> C.g\n \n >>> C.b\n 'b'\n >>> C.a\n 'a'\n >>> C.methods\n [, ]\n\nThe order that the metaclasses are composed is explicit as they act as\ntransformers over each other.\n\n\n``Template``\n--------------------\n\nWhile the previous example only showed metaclasses, you can use this for any\nclass; however, it is most useful for metaclasses where having a compatible\nmetaclass hierarchy is important.\n\nA ``Template`` is a callable that takes a ``type`` object and\nreturns a new ``type`` object. It takes the following arguments:\n\n- ``base``: A type object. ``default``: ``type``.\n- ``adjust_name``: Should we prepend the name of the ``base`` to the\n new type object. ``default``: ``True``.\n\nThese can be chained together with any concrete metaclass at the end,\ne.g.:\n\n.. code:: python\n\n new_class = m(n,p(q(...z(type)...)))\n\nYou can also use the compose function to do this:\n\n.. code:: python\n\n from metautils import compose\n\n new_class_template = compose(m, n, p, q, ..., z)", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/quantopian/metautils", "keywords": null, "license": "Apache 2.0", "maintainer": null, "maintainer_email": null, "name": "metautils", "package_url": "https://pypi.org/project/metautils/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/metautils/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/quantopian/metautils" }, "release_url": "https://pypi.org/project/metautils/0.1.2/", "requires_dist": null, "requires_python": null, "summary": "Utilities for working with metaclasses.", "version": "0.1.2" }, "last_serial": 2062843, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "ca17c2089c03b65437f01613cb68475e", "sha256": "40211ff433d6e770631923fe37e09cb138d15197ea1ff24b444e1b8cdd7643af" }, "downloads": -1, "filename": "metautils-0.1.0.tar.gz", "has_sig": false, "md5_digest": "ca17c2089c03b65437f01613cb68475e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6622, "upload_time": "2015-06-05T18:56:35", "url": "https://files.pythonhosted.org/packages/2a/d4/297358f6a20ac78cb4f4343da60d3877d8d026328a121ece78da1929790b/metautils-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "9ba8da390d7d3310ac1b2a5c5e4eea7a", "sha256": "c39c790d14cac0afb62ca5e095be54298e0796b7b30ced3053f46eea61073782" }, "downloads": -1, "filename": "metautils-0.1.1.tar.gz", "has_sig": false, "md5_digest": "9ba8da390d7d3310ac1b2a5c5e4eea7a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6929, "upload_time": "2015-06-05T18:59:24", "url": "https://files.pythonhosted.org/packages/0f/be/dc84292111a40741da28583d91679ac385882eef66ade009c1a45c363e68/metautils-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "4d76ef1851cb9783ba971c3f2d273dc7", "sha256": "6ad999cdcaf4fdc5a1bbe362551355bab2debb1253dc3d294a0b836f340906d8" }, "downloads": -1, "filename": "metautils-0.1.2.tar.gz", "has_sig": false, "md5_digest": "4d76ef1851cb9783ba971c3f2d273dc7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8611, "upload_time": "2016-04-13T23:28:09", "url": "https://files.pythonhosted.org/packages/01/4c/e8203e09d06db17cbc3aeb038a1789bc8526e71873552b54a1b011244b7c/metautils-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4d76ef1851cb9783ba971c3f2d273dc7", "sha256": "6ad999cdcaf4fdc5a1bbe362551355bab2debb1253dc3d294a0b836f340906d8" }, "downloads": -1, "filename": "metautils-0.1.2.tar.gz", "has_sig": false, "md5_digest": "4d76ef1851cb9783ba971c3f2d273dc7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8611, "upload_time": "2016-04-13T23:28:09", "url": "https://files.pythonhosted.org/packages/01/4c/e8203e09d06db17cbc3aeb038a1789bc8526e71873552b54a1b011244b7c/metautils-0.1.2.tar.gz" } ] }