This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ZeroDivisionError class should have a __name__ attr
Type: Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: jcrmatos, steven.daprano
Priority: normal Keywords:

Created on 2019-01-27 10:24 by jcrmatos, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg334416 - (view) Author: (jcrmatos) * Date: 2019-01-27 10:24
Hello,

When trying this
try:
    1/0
except Exception as exc:
    print(type(exc))  # returns <class 'ZeroDivisionError'>
    print(exc.__name__)  # returns AttributeError: 'ZeroDivisionError' object has no attribute '__name__'

I believe all classes should have a __name__ attr, correct?

It would be nice to check all the other exceptions to see if any other is also missing the __name__ attr.

Thanks,

JM
msg334418 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2019-01-27 11:19
You are not looking at the class, you are looking at an instance:

py> exc = ZeroDivisionError('divide by zero')
py> type(exc).__name__
'ZeroDivisionError'
py> exc.__name__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'ZeroDivisionError' object has no attribute '__name__'
msg334419 - (view) Author: (jcrmatos) * Date: 2019-01-27 11:32
Hello,

You are correct. My bad.

Thanks,

JM
History
Date User Action Args
2022-04-11 14:59:10adminsetgithub: 80017
2019-01-27 11:32:51jcrmatossetmessages: + msg334419
2019-01-27 11:20:00steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg334418

resolution: not a bug
stage: resolved
2019-01-27 10:24:57jcrmatoscreate