Your original proposal appears to want this behavior:
class BaseException:
def __call__(self):
raise self
That could be expanded to something like:
class BaseException:
def __call__(self, *args):
if not args:
raise self
if len(args) > 1:
TypeError(f"{self} expects at most one argument")() # this adds
yet another call level
raise self from args[0]
@staticmethod
def reraise():
raise
Why, though? One would usually want to raise the exception at the same call
level of the invalid operation, not an extra one. Also, the raise statement
makes it clear that something went wrong, and is easily recognized by static
code analysers.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/P3AHT7LKQ5QATZN5KUJVMPUEVSYWF4OH/
Code of Conduct: http://python.org/psf/codeofconduct/