{ "info": { "author": "Martin Teichmann", "author_email": "lkb.teichmann@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: Python Software Foundation License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "metaclass - Writing and using metaclasses\n==========================================\n\nMetaclasses are a very powerful tool in Python. You can control\nthe entire class creation process with them.\n\nMost of the time, however, they are too powerful. This module helps\nyou to use some of the advantages of metaclasses, without having\nto know all the details. It defines a base class `SubclassInit`.\nInheriting from this class one can modify the subclass creation\nprocess.\n\nInitializing subclasses\n-----------------------\n\nA very common usecase for a metaclass is that you just want to execute\nsome code after a class is created. This can easily done with\n``SubclassInit``. You just define a method ``__init_subclass__``,\nwhich is implicitly considered a ``@classmethod`` and\nwill be called after each subclass that is generated of your\nclass. As a parameter it gets the namespace of the class. An example\nis a simple subclass registration::\n\n class Register(SubclassInit):\n subclasses = []\n\n def __subclass_init__(cls, ns, **kwargs):\n super().__subclass_init__(ns, **kwargs)\n Register.subclasses.append(cls)\n\nNote how you can add keyword arguments. Those are the keyword\narguments given on the class definition line, as in::\n\n class Subclass(Base, spam=\"ham\"):\n pass\n\nDon't forget to properly call ``super()``! Other classes may want to\ninitialize subclasses as well. This is also why you should pass over\nthe keyword arguments, just taking out the ones you need.\n\nInitializing Descriptors\n------------------------\n\nDescriptors are a powerful technique to create object attributes which\ncalculate their value on-the-fly. A property is a simple example of such\na descriptor. There is a common problem with those descriptors: they\ndo not know their name. Using ``SubclassInit`` you can add an\n``__init_descriptor__`` method to a descriptor which gets called once the\nclass is ready and the descriptor's name is known.\n\nAs an example, we can define a descriptor which makes an attribute a\nweak reference::\n\n import weakref\n\n class WeakAttribute:\n def __get__(self, instance, owner):\n return instance.__dict__[self.name]()\n\n def __set__(self, instance, value):\n instance.__dict__[self.name] = weakref.ref(value)\n\n def __init_descriptor__(self, owner, name):\n self.name = name\n\nOrder of Attributes\n-------------------\n\nSometimes one is interested in which order the attributes were defined\nin the class. ``SubclassInit`` leaves a tuple with all the names of the\nattributes in the order they were defined as a class attribute called\n``__attribute_order__``. Note that Python already defines some class\nattributes, like ``__module__``, some of which also show up in this\ntuple.\n\nAs an example::\n\n class AttributeOrder(SubclassInit):\n a = 1\n\n def b(self):\n pass\n\n c = 5\n\n assert AttributeOrder.__attribute_order__ == \\\n ('__module__', '__qualname__', 'a', 'b', 'c')\n", "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/tecki/metaclasses", "keywords": null, "license": "PSF", "maintainer": null, "maintainer_email": null, "name": "metaclass", "package_url": "https://pypi.org/project/metaclass/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/metaclass/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/tecki/metaclasses" }, "release_url": "https://pypi.org/project/metaclass/1.3/", "requires_dist": null, "requires_python": null, "summary": "Useful baseclasses for metaclasses", "version": "1.3" }, "last_serial": 1941598, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "d17941e5764e5c28a8a955f3ccba7515", "sha256": "aafb66cfc251a1ffa040e02e597838a15473db267eb515cbcd1696f97255e249" }, "downloads": -1, "filename": "metaclass-1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "d17941e5764e5c28a8a955f3ccba7515", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 3377, "upload_time": "2015-02-27T16:05:39", "url": "https://files.pythonhosted.org/packages/02/81/69f9d03eb05ec309df9cc8e65c500021685db224a53cd374a2ce96c29028/metaclass-1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7119f7f76c2a2059da67b74a43ef6091", "sha256": "c981ae0a4ae214c5087c46b67795b0fe0c0fd21b8f066ebd250ae57f8e270030" }, "downloads": -1, "filename": "metaclass-1.0.tar.gz", "has_sig": false, "md5_digest": "7119f7f76c2a2059da67b74a43ef6091", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2325, "upload_time": "2015-02-27T16:05:42", "url": "https://files.pythonhosted.org/packages/6a/a5/d32ffe74f696ee31f1c96ec1090a4a1d1d8ebd85bbf98851db0a7065eb9d/metaclass-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "a2ed2be653c2918abf7064edc894cd28", "sha256": "265990f33e2670dd75cdc3a1b88d4961811fb795dbad5f94452b506849d85c23" }, "downloads": -1, "filename": "metaclass-1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a2ed2be653c2918abf7064edc894cd28", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 3107, "upload_time": "2015-03-15T16:01:41", "url": "https://files.pythonhosted.org/packages/9a/c8/8d9717d3a1cc663f8250fb9b022ae586b7632efc9e9937af59123b7d9ab0/metaclass-1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3a10459641400cfc34a5c6e67ebd4889", "sha256": "b36e5b33a9503326f2c610f701e70fba0637738db0731d2f91eedb34144fbfb7" }, "downloads": -1, "filename": "metaclass-1.1.tar.gz", "has_sig": false, "md5_digest": "3a10459641400cfc34a5c6e67ebd4889", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2054, "upload_time": "2015-03-15T16:01:45", "url": "https://files.pythonhosted.org/packages/62/68/35803edf20da6729a93f1044dcbb7ea15ef12acdaf1b75d12391ad27d77e/metaclass-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "1b81fe0ef8cf62c560131defdce8b55c", "sha256": "c2e1a345e921f563a835f509ff1bd286cbd4b1480bafe69ea3d28c482cf319de" }, "downloads": -1, "filename": "metaclass-1.2.tar.gz", "has_sig": false, "md5_digest": "1b81fe0ef8cf62c560131defdce8b55c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2634, "upload_time": "2016-02-04T18:18:55", "url": "https://files.pythonhosted.org/packages/7e/a0/9785c8961cf9fbf10847c4b2876d03cf86a646e91fd73089a1b288d3f6c0/metaclass-1.2.tar.gz" } ], "1.3": [ { "comment_text": "", "digests": { "md5": "4b4beda5c9715eb7fdff36266759f465", "sha256": "60b84df22c68d320d0e1fc97a48859e36203e103244e3dfe801ce11c692e0dae" }, "downloads": -1, "filename": "metaclass-1.3.tar.gz", "has_sig": false, "md5_digest": "4b4beda5c9715eb7fdff36266759f465", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2681, "upload_time": "2016-02-05T14:06:01", "url": "https://files.pythonhosted.org/packages/c9/8f/007b17417e85ea1df7d2a92cbbf2cffbf83b0c8deac7830d6fdf11d50bef/metaclass-1.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4b4beda5c9715eb7fdff36266759f465", "sha256": "60b84df22c68d320d0e1fc97a48859e36203e103244e3dfe801ce11c692e0dae" }, "downloads": -1, "filename": "metaclass-1.3.tar.gz", "has_sig": false, "md5_digest": "4b4beda5c9715eb7fdff36266759f465", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2681, "upload_time": "2016-02-05T14:06:01", "url": "https://files.pythonhosted.org/packages/c9/8f/007b17417e85ea1df7d2a92cbbf2cffbf83b0c8deac7830d6fdf11d50bef/metaclass-1.3.tar.gz" } ] }