Skip to content

Add fixture for ValueError.message to futurize #609

@CarstenGrohmann

Description

@CarstenGrohmann

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions