Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fixture for ValueError.message to futurize #609

Open
CarstenGrohmann opened this issue Nov 13, 2022 · 0 comments
Open

Add fixture for ValueError.message to futurize #609

CarstenGrohmann opened this issue Nov 13, 2022 · 0 comments

Comments

@CarstenGrohmann
Copy link

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

  • up-to-date ArchLinux on x86_64
  • Python 3.10.8 (main, Oct 13 2022, 21:13:48) [GCC 12.2.0]
  • futurize 0.18.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant