Package: pypoison
pypoisonNothing says "DO NOT USE" like a poison value.Sometimes you need a value to represent absence of a value.
However, sometimes you want to make absolutely sure this value is not used in any way, shape, form, or anything whatsoever.
In these cases, values likeNone,float('NaN'), orFalsedon't really fit, because you can still "touch" these values.That's what poison values are for.
Because nothing says "DO NOT USE" like a poison value.This module provides an object that overrides all methods to raise an exception.Table of ContentsInstallUsageCaveatsTODOsContributeInstallJustpip install pypoison. (As soon as I have uploaded it to PyPI.)Or just copypypoison/__init__.pyto your project aspypoison.py.There are no dependencies.UsageJust use the value returned bypypoison.get_poison()when you need a poison value.The object is always the same object.Custom behaviorBy default, all accesses raise aValueErrorwith a human-readable
explanation which attribute/method was accessed.If you prefer otherwise, you can callpypoison.set_exception(my_exception),
and the poison value now raises the objectmy_exceptionwhenever anything is done with the poison value.For extra fanciness, you can callpypoison.set_handler(my_fn),
and the poison value will raise whatevermy_fn(method_name)returns.To reset to the default behavior, you can callpypoison.set_exception(None)Examples>>>1inpypoison.get_poison()ValueError:Triedtoaccess__contains__onpoisonvalue.>>>pypoison.get_poison()/1ValueError:Triedtoaccess__truediv__onpoisonvalue.>>>1+Foo()ValueError:Triedtoaccess__radd__onpoisonvalue.>>>pypoison.get_poison()*4ValueError:Triedtoaccess__mul__onpoisonvalue.>>>pypoison.get_poison()%3ValueError:Triedtoaccess__mod__onpoisonvalue.>>>3%pypoison.get_poison()ValueError:Triedtoaccess__rmod__onpoisonvalue.>>>'{}'.format(pypoison.get_poison())ValueError:Triedtoaccess__format__onpoisonvalue.>>>'{!r}'.format(pypoison.get_poison())ValueError:Triedtoaccess__repr__onpoisonvalue.>>>list(pypoison.get_poison())ValueError:Triedtoaccess__iter__onpoisonvalue.>>>help(pypoison.get_poison())ValueError:Triedtoaccess__getattribute__onpoisonvalue.>>>pypoison.get_poison()==42ValueError:Triedtoaccess__eq__onpoisonvalue.CaveatSeriousHeavy use of theinspectmodule might fiddle around with the poison object,
however safeguards are in place to make sure that this is not easy.Passive use, such asisor storing it in a passive container (e.g. a list)
cannot be prevented.  However, this is intentionl. This module wants to
provide a poisonous placeholder value, and not an actively malicious value.I am not sure how to handlecallable(),id(), andtype().Logically-null usage cannot be detected, such as inpypoison.get_poison() in []orTrue or pypoison.get_poison()or evenmax([pypoison.get_poison()]).This modulemay cause bugsin your debugger/IDE/editor.  Or at least unexpected behavior.Do not store the poison value in a global.  Many tools, e.g. unittest,
walk the global variables and inspect them.Non-seriousThe amount of black magic mightpoisonyour appreciation of Python.Pythonidae are alwaysnonvenomous; this module makes itpoisonous!TODOsDo weird stuff with itContributeFeel free to dive in!Open an issueor submit PRs.