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 2to3 tool #99394

Closed
CarstenGrohmann opened this issue Nov 11, 2022 · 2 comments
Closed

Add fixture for ValueError.message to 2to3 tool #99394

CarstenGrohmann opened this issue Nov 11, 2022 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@CarstenGrohmann
Copy link

Bug report

Please extend the 2to3 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

$ 2to3 example.py2 
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored example.py2
--- 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" % 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]
@CarstenGrohmann CarstenGrohmann added the type-bug An unexpected behavior, bug, or error label Nov 11, 2022
@JelleZijlstra
Copy link
Member

2to3 is no longer maintained and will be removed from CPython in the future. Perhaps third-party tools like https://python-future.org/futurize.html would be open to adding such a converter.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Nov 11, 2022
@CarstenGrohmann
Copy link
Author

Issue reported to : PyCQA/modernize#261 and PythonCharmers/python-future#609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants