New submission from YoSTEALTH <rit...@stealthcentral.com>:

class Some_Class:

    def error(self):
        if not getattr(self, 'boo', None):
            raise Exception(f'`class {self.__class__.__name__}:` raised some 
error!')


something = Some_Class()
something.error()


# This is how Error looks
# -----------------------
Traceback (most recent call last):
  File "/test.py", line 9, in <module>
    something.error()
  File "/test.py", line 5, in error
    raise Exception(f'`class {self.__class__.__name__}:` raised some error!')
Exception: `class Some_Class:` raised some error!


# This is how Error should look
# -----------------------------
Traceback (most recent call last):
  File "/test.py", line 9, in <module>
    something.error()
  File "/test.py", line 5, in error
    raise Exception(...)
Exception: `class Some_Class:` raised some error!


When a developer manually raises an error they want the user/developer 
debugging the error to see the final, nicely formatted error message itself 
"Exception: `class Some_Class:` raised some error!" not the ugly formating of 
the error message itself "raise Exception(f'`class {self.__class__.__name__}:` 
raised some error!')" which can also lead to confusion, thus it should be 
hidden as "raise Exception(...)"

It could also be said that "raise Exception(...)" shouldn't even be shown but 
what raises this error condition "if not getattr(self, 'boo', None):" but this 
seems more work so i am keeping it simple by saying lets just hide the ugly 
formatting part.

----------
components: Interpreter Core
messages: 358413
nosy: YoSTEALTH
priority: normal
severity: normal
status: open
title: Hide manually raised exception formatting
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39053>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to