{ "info": { "author": "Ben Wiederhake", "author_email": "BenWiederhake.GitHub@gmx.de", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# pypoison\n\n> Nothing says \"DO NOT USE\" like a poison value.\n\nSometimes you need a value to represent absence of a value.\nHowever, sometimes you want to make absolutely sure this value is not used in any way, shape, form, or anything whatsoever.\nIn these cases, values like `None`, `float('NaN')`, or `False` don't really fit, because you can still \"touch\" these values.\n\nThat's what poison values are for.\nBecause nothing says \"DO NOT USE\" like a poison value.\n\nThis module provides an object that overrides all methods to raise an exception.\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n- [Caveats](#caveats)\n- [TODOs](#todos)\n- [Contribute](#contribute)\n\n## Install\n\nJust `pip install pypoison`. (As soon as I have uploaded it to PyPI.)\n\nOr just copy `pypoison/__init__.py` to your project as `pypoison.py`.\n\nThere are no dependencies.\n\n## Usage\n\nJust use the value returned by `pypoison.get_poison()` when you need a poison value.\n\nThe object is always the same object.\n\n### Custom behavior\n\nBy default, all accesses raise a `ValueError` with a human-readable\nexplanation which attribute/method was accessed.\n\nIf you prefer otherwise, you can call `pypoison.set_exception(my_exception)`,\nand the poison value now raises the object `my_exception`\nwhenever anything is done with the poison value.\n\nFor extra fanciness, you can call `pypoison.set_handler(my_fn)`,\nand the poison value will raise whatever `my_fn(method_name)` returns.\n\nTo reset to the default behavior, you can call `pypoison.set_exception(None)`\n\n### Examples\n\n```python\n>>> 1 in pypoison.get_poison()\nValueError: Tried to access __contains__ on poison value.\n>>> pypoison.get_poison() / 1\nValueError: Tried to access __truediv__ on poison value.\n>>> 1 + Foo()\nValueError: Tried to access __radd__ on poison value.\n>>> pypoison.get_poison() * 4\nValueError: Tried to access __mul__ on poison value.\n>>> pypoison.get_poison() % 3\nValueError: Tried to access __mod__ on poison value.\n>>> 3 % pypoison.get_poison()\nValueError: Tried to access __rmod__ on poison value.\n>>> '{}'.format(pypoison.get_poison())\nValueError: Tried to access __format__ on poison value.\n>>> '{!r}'.format(pypoison.get_poison())\nValueError: Tried to access __repr__ on poison value.\n>>> list(pypoison.get_poison())\nValueError: Tried to access __iter__ on poison value.\n>>> help(pypoison.get_poison())\nValueError: Tried to access __getattribute__ on poison value.\n>>> pypoison.get_poison() == 42\nValueError: Tried to access __eq__ on poison value.\n```\n\n## Caveat\n\n### Serious\n\nHeavy use of the `inspect` module might fiddle around with the poison object,\nhowever safeguards are in place to make sure that this is not easy.\n\nPassive use, such as `is` or storing it in a passive container (e.g. a list)\ncannot be prevented. However, this is intentionl. This module wants to\nprovide a poisonous placeholder value, and not an actively malicious value.\n\nI am not sure how to handle `callable()`, `id()`, and `type()`.\n\nLogically-null usage cannot be detected, such as in `pypoison.get_poison() in []`\nor `True or pypoison.get_poison()` or even `max([pypoison.get_poison()])`.\n\nThis module [may cause bugs](https://github.com/bpython/bpython/issues/776)\nin your debugger/IDE/editor. Or at least unexpected behavior.\n\nDo not store the poison value in a global. Many tools, e.g. unittest,\nwalk the global variables and inspect them.\n\n### Non-serious\n\nThe amount of black magic might *poison* your appreciation of Python.\n\nPythonidae are always *[nonvenomous](https://en.wikipedia.org/wiki/Pythonidae)*; this module makes it *poisonous*!\n\n## TODOs\n\n* Do weird stuff with it\n\n## Contribute\n\nFeel free to dive in! [Open an issue](https://github.com/BenWiederhake/pypoison/issues/new) or submit PRs.\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/BenWiederhake/pypoison", "keywords": "pypoison", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "pypoison", "package_url": "https://pypi.org/project/pypoison/", "platform": "Any", "project_url": "https://pypi.org/project/pypoison/", "project_urls": { "Homepage": "https://github.com/BenWiederhake/pypoison" }, "release_url": "https://pypi.org/project/pypoison/0.0.1/", "requires_dist": null, "requires_python": "", "summary": "Nothing says \"DO NOT USE\" like a poison value.", "version": "0.0.1" }, "last_serial": 5543120, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "1f79f956e4dd52a8cfadfa393410f38a", "sha256": "32fecfdf0986b1ba1f49cea6ed39825338499181dd8a3e340e748a5421e6bfe9" }, "downloads": -1, "filename": "pypoison-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "1f79f956e4dd52a8cfadfa393410f38a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5535, "upload_time": "2019-07-16T23:15:24", "url": "https://files.pythonhosted.org/packages/89/d5/0d985b5cfdeb2f38527416499e53cc53a04311f72ff3a338e98d6394fe8e/pypoison-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7b44748539e5d33eae827cb22f96fbe9", "sha256": "0040b42f488bcea8011151049113affea65f9d67534db107e1fc20bf215be84d" }, "downloads": -1, "filename": "pypoison-0.0.1.tar.gz", "has_sig": false, "md5_digest": "7b44748539e5d33eae827cb22f96fbe9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4330, "upload_time": "2019-07-16T23:17:11", "url": "https://files.pythonhosted.org/packages/6b/ca/95207ab48789aedc87943c3ea4fd1a09e84805152ff5a9fbd1a677b432d2/pypoison-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1f79f956e4dd52a8cfadfa393410f38a", "sha256": "32fecfdf0986b1ba1f49cea6ed39825338499181dd8a3e340e748a5421e6bfe9" }, "downloads": -1, "filename": "pypoison-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "1f79f956e4dd52a8cfadfa393410f38a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5535, "upload_time": "2019-07-16T23:15:24", "url": "https://files.pythonhosted.org/packages/89/d5/0d985b5cfdeb2f38527416499e53cc53a04311f72ff3a338e98d6394fe8e/pypoison-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7b44748539e5d33eae827cb22f96fbe9", "sha256": "0040b42f488bcea8011151049113affea65f9d67534db107e1fc20bf215be84d" }, "downloads": -1, "filename": "pypoison-0.0.1.tar.gz", "has_sig": false, "md5_digest": "7b44748539e5d33eae827cb22f96fbe9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4330, "upload_time": "2019-07-16T23:17:11", "url": "https://files.pythonhosted.org/packages/6b/ca/95207ab48789aedc87943c3ea4fd1a09e84805152ff5a9fbd1a677b432d2/pypoison-0.0.1.tar.gz" } ] }