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: 2to3 exception handling
Type: Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: iritkatriel, shihai1991, xxm
Priority: normal Keywords:

Created on 2019-07-30 08:24 by xxm, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
labeled_lda.py xxm, 2019-07-30 08:24 The project Labeled-LDA-Python (https://github.com/JoeZJH/Labeled-LDA-Python )can work well in Python2. We use 2to3 to convert it into Python3 code. Then the AttributeError shows up
Messages (3)
msg348720 - (view) Author: Xinmeng Xia (xxm) Date: 2019-07-30 08:24
we run the converted Python3 code, the following error will happen:
Traceback (most recent call last):
  File "/home/xxm/Desktop/instrument/datasetpy3/Labeled-LDA-Python/example.py", line 50, in <module>
    llda_model.save_model_to_dir(save_model_dir)
  File "/home/xxm/Desktop/instrument/datasetpy3/Labeled-LDA-Python/model/labeled_lda.py", line 697, in save_model_to_dir
    LldaModel._write_object_to_file(save_model_path, save_model.__dict__)
  File "/home/xxm/Desktop/instrument/datasetpy3/Labeled-LDA-Python/model/labeled_lda.py", line 650, in _write_object_to_file
    print(("%s\n\t%s" % (message, e.message)))
AttributeError: 'TypeError' object has no attribute 'message'

it seems that attributes change between Python2 and Python3. However 2to3 lack for this fix when dealing with exception fix.
msg349178 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2019-08-07 17:31
1. the message property of PyBaseExceptionObject(Exception) have been cancelled.

[1] https://github.com/python/cpython/blob/2.7/Include/pyerrors.h#L13
[2] https://github.com/python/cpython/blob/master/Include/cpython/pyerrors.h#L18

2. `except Exception, e` is a python2.x behavior, pls use `except Exception as e` in python3.x
msg381857 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-11-25 18:19
Right, the message field on exceptions was removed in python 3 (it was deprecated since Python 2.6).

2to3 can't automatically fix this, because as a static translator it doesn't know that the object on which you are accessing .message is an exception.
History
Date User Action Args
2022-04-11 14:59:18adminsetgithub: 81899
2020-11-25 18:19:26iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg381857

resolution: wont fix
stage: resolved
2019-08-07 17:31:16shihai1991setnosy: + shihai1991
messages: + msg349178
2019-07-30 08:24:58xxmcreate