PythonCharmers / python-future

Easy, clean, reliable Python 2/3 compatibility
http://python-future.org
MIT License
1.17k stars 291 forks source link

Add fixture for ValueError.message to futurize #609

Open CarstenGrohmann opened 1 year ago

CarstenGrohmann commented 1 year ago

Bug report

Please extend the futurize tool to display a warning when ValueError.message is used, or replace the message attribute e.g. with str(<exception>), since ValueError.message no longer exists in Python 3.

Reproducer

$ cat example.py2
#!/usr/bin/env python2.7
try:
    raise ValueError('Foo')
except ValueError as e:
    print "Caught: %s" % e.message

$ futurize example.py2 
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored example.py2
--- example.py2 (original)
+++ example.py2 (refactored)
@@ -1,5 +1,6 @@
 #!/usr/bin/env python2.7
+from __future__ import print_function
 try:
     raise ValueError('Foo')
 except ValueError as e:
-    print "Caught: %s" % e.message
+    print("Caught: %s" % e.message)
RefactoringTool: Files that need to be modified:
RefactoringTool: example.py2

Example of an expected result

--- example.py2 (original)
+++ example.py2 (refactored)
@@ -2,4 +2,4 @@
 try:
     raise ValueError('Foo')
 except ValueError as e:
-    print "Caught: %s" % e.message
+    print("Caught: %s" % str(e))

My environment