On Mon, May 24, 2021 at 09:49:13PM -0000, Joren wrote: > It's unfortunate that there is no way to have e.g. `'spam' in > my_symbolic_set` evaluate to something else than a boolean. Also, this > approach will not work with everything else for which there is no > dunder method, e.g. `math.sin(my_symbolic_value)` cannot be tricked > into returning a Symbol.
Monkey-patching to the rescue. import math from math import sin as _sin def my_sin(x): if isinstance(x, Symbol): ... else: return _sin(x) math.sin = my_sin Obligatory link to: https://avdi.codes/why-monkeypatching-is-destroying-ruby/ -- Steve _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/CDIPDFAAVDKVD2JRRKHZTWSJOOYYON2P/ Code of Conduct: http://python.org/psf/codeofconduct/