On 11 October 2016 at 17:21, David Navarro <davis...@gmail.com> wrote: > Something like this > > In [1]: def a(): pass > In [2]: def r(): raise RuntimeError('Do not forget to call this') > In [3]: a.__bool__ = r > In [4]: if a: pass > > I don't have an environment to test if this is possible. This would allow > marking with a decorator functions that might be misleading or that are a > common source of issues for new users.
It would need to be somewhat more complex (the above doesn't work as it stands, because __bool__ is only recognised as a method on a class, not an attribute of a function). But it's doable, either manually (make a a class with __call__ and __bool__) or semi-automatically (a decorator that creates a class for which __call__ is defined as running the decorated function, and __bool__ raises a warning). Paul _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/